'nMin = Sheets("Sheet1").Range("A1") 'nMax = Sheets("Sheet1").Range("A2") Option Explicit
Sub LottoSpecial(Num As Long, TargetVal As Long) Dim a As Integer, _ b As Integer, _ c As Integer, _ d As Integer, _ e As Integer, _ f As Integer Dim Counter As Long, _ NumCols As Long, _ i As Long Dim arrResults Application.ScreenUpdating = False For a = 1 To Num - 5 For b = a + 1 To Num - 4 For c = b + 1 To Num - 3 For d = c + 1 To Num - 2 For e = d + 1 To Num - 1 For f = e + 1 To Num If a + b + c + d + e + f = TargetVal Then Application.StatusBar = Counter Counter = Counter + 1 With ActiveSheet If Counter Mod 65536 = 0 Then .Cells(65536, i + 1) = a & "," & b & "," & c & "," & d & "," & e & "," & f i = i + 1 Else .Cells(Counter Mod 65536, i + 1) = a & "," & b & "," & c & "," & d & "," & e & "," & f End If End With End If Next f Next e Next d Next c Next b Next a Application.StatusBar = False Application.ScreenUpdating = True End Sub
Sub MultipleLottoSums()
Dim nMin As Integer, _ nMax As Integer
Dim i As Long Dim Wks As Worksheet
nMin = Sheets("Sheet1").Range("A1") nMax = Sheets("Sheet1").Range("A2")
With ThisWorkbook For i = nMin To nMax Set Wks = .Worksheets.Add With Wks .Activate .Name = "Sum_to_" & i Call LottoSpecial(45, i) End With Next i End With End Sub |