adding the comment will prevent checking your history.
for checking sum see code in green below
Sub allgen()
Dim gd(35) ' array for generated data
Dim hd(35) ' array for historical data
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim sor_szam As Integer
Dim gorgo As Variant
'Munka1.Range("L3:R100").ClearContents
timebegin = Now()
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Application.StatusBar = "Executing..."
Randomize Timer
For i = 3 To 103
rejected: ' matches previous draw try again
For J = 1 To 7
If J = 1 Then 'elso szám generálása
ag = Int((35 - 1 + 1) * Rnd + 1)
Cells(i, 12) = ag
End If
If J = 2 Then 'második szám generálása
bg = Int((35 - 1 + 1) * Rnd + 1)
Do While bg = ag
bg = Int((35 - 1 + 1) * Rnd + 1)
Loop
Cells(i, 13) = bg
End If
If J = 3 Then 'harmadik szám generálása
cg = Int((35 - 1 + 1) * Rnd + 1)
Do While cg = ag Or cg = bg
cg = Int((35 - 1 + 1) * Rnd + 1)
Loop
Cells(i, 14) = cg
End If
If J = 4 Then 'negyedik szám generálása
dg = Int((35 - 1 + 1) * Rnd + 1)
Do While dg = ag Or dg = bg Or dg = cg
dg = Int((35 - 1 + 1) * Rnd + 1)
Loop
Cells(i, 15) = dg
End If
If J = 5 Then 'ötödik szám generálása
eg = Int((35 - 1 + 1) * Rnd + 1)
Do While eg = ag Or eg = bg Or eg = cg Or eg = dg
eg = Int((35 - 1 + 1) * Rnd + 1)
Loop
Cells(i, 16) = eg
End If
If J = 6 Then 'hatodik szám generálása
fg = Int((35 - 1 + 1) * Rnd + 1)
Do While fg = ag Or fg = bg Or fg = cg Or fg = dg Or fg = eg
fg = Int((35 - 1 + 1) * Rnd + 1)
Loop
Cells(i, 17) = fg
End If
If J = 7 Then 'hetedik szám generálása
gg = Int((35 - 1 + 1) * Rnd + 1)
Do While gg = ag Or gg = bg Or gg = cg Or gg = dg Or gg = eg Or gg = fg
gg = Int((35 - 1 + 1) * Rnd + 1)
Loop
Cells(i, 18) = gg
End If
Next J
'
' lets filter for sum first as it takes a lot less time and no need to check history if otherwise rejected
draw_sum = ag + bg + cg + dg + eg + fg + gg
If draw_sum < 87 Or draw_sum > 157 Then GoTo rejected
' check historical data for match ag-gg is data being tested
' first clear the array variables
For q = 1 To 35: hd(q) = 0: gd(q) = 0: Next q
gd(ag) = 1: gd(bg) = 1: gd(cg) = 1: gd(dg) = 1: gd(eg) = 1: gd(fg) = 1: gd(gg) = 1 ' load current guess to gd array
For hl = 3 To 103: ' number of draws to check
For dl = 1 To 7 ' number of data elements
a = Cells(hl, dl): hd(a) = 1
Next dl
'hd array has historical draw data
m = 0 ' this variable will hold matching digit count
For q = 1 To 35
If gd(q) = hd(q) Then m = m + 1
Next q
' if all digits match count will be 35
If m = 35 Then GoTo rejected ' if you want to reject based on 6 digits change 35 to 34 etc
' no match found so program continues to next historical data set
For q = 1 To 35: hd(q) = 0: Next q ' clear hd() array ready for next data set
Next hl
Next i
With ActiveSheet
FirstRow = 3 'change to 2 if there are headings
LastRow = .Cells(.Rows.Count, "L").End(xlUp).Row
For iRow = FirstRow To LastRow
With .Cells(iRow, "L").Resize(1, 7)
.Sort Key1:=.Columns(1), Order1:=xlAscending, Header:=x1No, OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight
End With
Next iRow
End With
Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
Set gorgo = ActiveSheet.UsedRange
End Sub