Hello.
I've found a VBA script that will randomly select a value from within a given range, and will exclude a range of values.
I am trying to modify it to exclude two ranges of values, but am pretty lost. Ideally what it will do is return an integer from the given range "excluding" the values given in Exclude1 and Exclude2.
Could someone help me tweak this?
I've found a VBA script that will randomly select a value from within a given range, and will exclude a range of values.
I am trying to modify it to exclude two ranges of values, but am pretty lost. Ideally what it will do is return an integer from the given range "excluding" the values given in Exclude1 and Exclude2.
Could someone help me tweak this?
Code:
Function RandBetweenInt(Lowest As Long, Highest As Long, Exclude1 As Range, Exclude2 As Range) As Long
Dim R As Long
Dim C As Range
Do
R = Lowest + Int(Rnd() * (Highest + 1 - Lowest))
For Each C In Exclude1
If R = C Then Exit For
Next C
Loop Until C Is Nothing
RandBetweenInt = R
Application.Volatile
End Function