Option Explicit
Sub test()
Dim t As Single, n As Byte, x As New Collection, i As Byte, x2 As New Collection, z As Byte
Range("A1:E18").ClearContents
Application.ScreenUpdating = False
debut:
t = Timer
Set x = Nothing
Set x2 = Nothing
Randomize
For i = 1 To 18
Do While x.Count < 5
If Timer > t + 0.2 Then GoTo debut
On Error Resume Next
n = Int(90 * Rnd) + 1
z = IIf(Int(n / 10) = 9, 8, Int(n / 10))
x.Add z, CStr(z)
If Err.Number = 0 Then
x2.Add n, CStr(n)
If Err.Number = 0 Then
Cells(i, x.Count).Value = n
Else
x.Remove x.Count
End If
End If
Loop
On Error GoTo 0
Set x = Nothing
Next i
For i = 1 To 18
Range(Cells(i, 1), Cells(i, 5)).Sort Key1:=Cells(i, 1), Order1:=xlAscending, _
Orientation:=xlLeftToRight
Next i
Application.ScreenUpdating = True
End Sub