List out 6 45 lottery combinations only those with the sum what you like

List out 6 45 lottery combinations only those with the sum what you like

gained some $$$ in this Little VBA,,, Hope others will too experience Smile

 

Sub Combos_Sum()
‘ Find all the combinations of six integer numbers, each and every in the vary 1..49,
‘ that sum to the price of a desired general. A mix won’t have two
‘ numbers which might be the similar. Results are written to columns A..F of the
‘ energetic worksheet.
Dim Total As Integer
Dim N1 As Integer
Dim N2 As Integer, Sum2 As Integer
Dim N3 As Integer, Sum3 As Integer
Dim N4 As Integer, Sum4 As Integer
Dim N5 As Integer, Sum5 As Integer
Dim N6 As Integer
Dim iRow As Long

Total = CInt(EnterBox(“Enter desired total”, “Combos”, 60))
If Total = zero Then Exit Sub

iRow = zero
For N6 = (Total + 15) 6 To 49
For N5 = five To N6 – 1
Sum5 = N5 + N6
For N4 = four To N5 – 1
Sum4 = Sum5 + N4
For N3 = three To N4 – 1
Sum3 = Sum4 + N3
For N2 = 2 To N3 – 1
Sum2 = Sum3 + N2
N1 = Total – Sum2
If N1 < 1 Then Exit For
If N1 < N2 Then

If iRow = 65536 Then
MsgBox iRow & ” combinations found.”, vbInformation, “Combos”
Exit Sub
End If

iRow = iRow + 1

Cells(iRow, 1) = N1
Cells(iRow, 2) = N2
Cells(iRow, three) = N3
Cells(iRow, four) = N4
Cells(iRow, five) = N5
Cells(iRow, 6) = N6
End If
Next N2
Next N3
Next N4
Next N5
Next N6

MsgBox iRow & ” combinations found.”, vbInformation, “Combos”

End Sub

Updated: September 27, 2017 — 6:19 pm

Leave a Reply

Your email address will not be published. Required fields are marked *