robdgr
Verenigingslid
- Lid geworden
- 8 sep 2001
- Berichten
- 4.430
- Office versie
- Microsoft 365
In kolom O worden vijf getallen tussen 1 en 5 getrokken en in P en Q vijf getallen tussen 0 en 9. Meestal gaat het goed, maar een enkele keer blijft onderstaande macro hangen op de eerste of tweede opdracht. De macro luidt:
Wat zie ik over het hoofd?
Code:
Sub trek_getallen()
On Error Resume Next
Dim keuze As Integer, getal1 As Integer, getal2 As Integer, i As Integer
Application.ScreenUpdating = False
For i = 1 To 5
Do
keuze = Application.WorksheetFunction.Round(Rnd() * 4, 0) + 1
Loop Until Range("O1:O" & i).Find(keuze) Is Nothing
Range("O" & i) = keuze
Do
getal1 = Application.WorksheetFunction.Round(Rnd() * 9, 0)
Loop Until Range("P1:P" & i).Find(getal1) Is Nothing
Range("P" & i) = getal1
Do
getal2 = Application.WorksheetFunction.Round(Rnd() * 9, 0)
Loop Until Range("q1:q" & i).Find(getal2) Is Nothing
Range("q" & i) = getal2
Next i
Application.ScreenUpdating = True
End Sub