Can one of you guys take a look at my macro and tell me how to fix my problem..
My problem is I am getting numbers that repeat themselves in a row. Like double (9's) or double (18's), and I shouldn't be getting them.
Option Explicit
Function generateNumbers(pattern As String, lNum As Long, uNum As Long) As Variant
Dim i As Integer
Dim x() As Integer
Redim x(0 To Len(pattern) - 1) As Integer
For i = 1 To Len(pattern)
Select Case UCase(Mid(pattern, i, 1))
Case "E"
Do
x(i - 1) = WorksheetFunction.RandBetween(lNum, uNum)
Loop Until x(i - 1) Mod 2 = 0
Case "O"
Do
x(i - 1) = WorksheetFunction.RandBetween(lNum, uNum)
Loop Until x(i - 1) Mod 2 = 1
End Select
Next i
generateNumbers = x
End Function
Sub test()
Dim i As Long
Dim lNum As Long
Dim hNum As Long
Dim numCombos As Long
'Gave some input messages here
lNum = InputBox("What is the lower boundary?", "Lower bound", 1)
hNum = InputBox("What is the upper boundary?", "Upper bound", 53)
numCombos = InputBox("How many combinations to produce?", "Combinations", 100)
Application.ScreenUpdating = False
Range("A3:F" & Rows.Count).ClearContents
For i = 3 To numCombos + 2
Range("A" & i & ":F" & i).Value = _
generateNumbers(Range("I4").Value, lNum, hNum)
Next i
Application.ScreenUpdating = True
End Sub
Bookmarks