Option Explicit
Const u = 5
Const v = 59
Const mx = 3 'changed, to illustrate code doesn't lock up
Sub lottonumbers2() 'reposted with modification
Dim b() As Boolean, t
Dim c(), d As Object, a, w As String
Dim i&, j&, k&, x&, q&, nr&
t = Timer
nr = Range("A" & Rows.Count).End(xlUp).Row 'changed, to better define historical range
a = Range("A1:A" & nr)
Range("B2:C" & nr).ClearContents
Randomize
For j = 2 To nr
For q = 1 To mx
ReDim b(v), c(1 To u)
k = 0
Do
x = Int(Rnd * v) + 1
If b(x) = False Then
k = k + 1
b(x) = True
End If
Loop Until k = 5
k = 0
For i = 1 To v
If b(i) Then k = k + 1: c(k) = i: _
If i < 10 Then c(k) = "0" & c(k)
Next i
w = Join(c, "-")
'Cells(j, 2) = w 'added, for display purpose only
'Cells(j, 3) = q 'added, for display purpose only
If w = a(j, 1) Then
Cells(j, 2) = w
Cells(j, 3) = q
Exit For
End If
Next q
If Cells(j, 3) = "" Then Cells(j, 3) = mx
Next j
MsgBox Timer - t
End Sub