Dim intRandom as integer
Randomize
retVal = Int((9 * Rnd) + 1)
If retVal = 1 Then intRandom = 0
If retVal = 2 Then intRandom = 1
If retVal = 3 Then intRandom = 2
If retVal = 4 Then intRandom = 3
If retVal = 5 Then intRandom = 4
If retVal = 6 Then intRandom = 5
If retVal = 7 Then intRandom = 6
If retVal = 8 Then intRandom = 7
If retVal = 9 then intRandom = 8
NXSupport - Your one-stop source for computer help
Public Function GenerateRandom(minVal As Long, maxVal As Long) As Long
intr = -1
maxVal = maxVal + 1
If maxVal > 0 Then
If minVal >= maxVal Then
minVal = 0
End If
Else
minVal = 0
maxVal = 10
End If
Randomize (DatePart("s", Now) + DatePart("m", Now))
Do While (intr < minVal Or intr = maxVal)
intr = CLng(Rnd() * maxVal)
Loop
GenerateRandom = intr
End Function
Usage:
Debug.Print GenerateRandom(0, 8)