S
Samual
Any ideas why this code is not working - i am a complete
novice to VBA!!!
It should generate a random number and then check if that
numbers is unique and if it is not loop until it is.
Please help - this is causing me to lose hair!!
randball1: Range("Ball1") = Int(Rnd() * 49) + 1
randball2: Range("Ball2") = Int(Rnd() * 49) + 1
If Range("Ball2") = Range("Ball1") Then GoTo randball2
randball3: Range("Ball3") = Int(Rnd() * 49) + 1
If Range("Ball3") = Range("Ball1") Or Range("Ball2") Then
GoTo randball3
randball4: Range("Ball4") = Int(Rnd() * 49) + 1
If Range("Ball4") = Range("Ball1") Or Range("Ball2") Or
Range("Ball3") Then GoTo randball4
randball5: Range("Ball5") = Int(Rnd() * 49) + 1
If Range("Ball5") = Range("Ball1") Or Range("Ball2") Or
Range("Ball3") Or Range("ball4") Then GoTo randball5
randball6: Range("Ball6") = Int(Rnd() * 49) + 1
If Range("Ball6") = Range("Ball1") Or Range("Ball2") Or
Range("Ball3") Or Range("Ball4") Or Range("ball5") Then
GoTo randball6
novice to VBA!!!
It should generate a random number and then check if that
numbers is unique and if it is not loop until it is.
Please help - this is causing me to lose hair!!
randball1: Range("Ball1") = Int(Rnd() * 49) + 1
randball2: Range("Ball2") = Int(Rnd() * 49) + 1
If Range("Ball2") = Range("Ball1") Then GoTo randball2
randball3: Range("Ball3") = Int(Rnd() * 49) + 1
If Range("Ball3") = Range("Ball1") Or Range("Ball2") Then
GoTo randball3
randball4: Range("Ball4") = Int(Rnd() * 49) + 1
If Range("Ball4") = Range("Ball1") Or Range("Ball2") Or
Range("Ball3") Then GoTo randball4
randball5: Range("Ball5") = Int(Rnd() * 49) + 1
If Range("Ball5") = Range("Ball1") Or Range("Ball2") Or
Range("Ball3") Or Range("ball4") Then GoTo randball5
randball6: Range("Ball6") = Int(Rnd() * 49) + 1
If Range("Ball6") = Range("Ball1") Or Range("Ball2") Or
Range("Ball3") Or Range("Ball4") Or Range("ball5") Then
GoTo randball6