in excel=27 100% pick3=1000
Sub GenerateCombinations()
Dim lastDraw(1 To 3) As Integer
Dim pattern As String
Dim i As Integer, j As Integer, k As Integer
Dim n1 As Integer, n2 As Integer, n3 As Integer
Dim line As Long
Dim valid As Boolean
' Example: last draw 3, 5, 7
lastDraw(1) = 3
lastDraw(2) = 5
lastDraw(3) = 7
' Example of a pattern, can be changed to 27 patterns
pattern = "012"
' Clear previous results
Sheets("Sheet1").Range("A2:C10000").ClearContents
line = 2 ' Start at line 2 for output
' Loop through all possible combinations (000 to 999)
For n1 = 0 to 9
For n2 = 0 to 9
For n3 = 0 to 9
valid = True
' Evaluate default position 1
Select Case Mid(default, 1, 1)
Case "0"
If n1 <> lastDraw(1) Then valid = False
Case "1"
If n1 >= lastDraw(1) Then valid = False
Case "2"
If n1 <= lastDraw(1) Then valid = False
End Select
' Evaluate default position 2
Select Case Mid(default, 2, 1)
Case "0"
If n2 <> lastDraw(2) Then valid = False
Case "1"
If n2 >= lastDraw(2) Then valid = False
Case "2"
If n2 <= lastDraw(2) Then Valid = False
End Select
' Evaluates pattern position 3
Select Case Mid(pattern, 3, 1)
Case "0"
If n3 <> lastDraw(3) Then Valid = False
Case "1"
If n3 >= lastDraw(3) Then Valid = False
Case "2"
If n3 <= lastDraw(3) Then Valid = False
End Select
' If valid, write to the spreadsheet
If valid Then
Sheets("Sheet1").Cells(row, 1).Value = n1
Sheets("Sheet1").Cells(row, 2).Value = n2
Sheets("Sheet1").Cells(row, 3).Value = n3
row = row + 1
End If
Next n3
Next n2
Next n1
MsgBox "Filter applied with pattern " & pattern & ". Total combinations: " & (line - 2)
End Sub