I would like to list all combinations of 9 different variables.
Each variable is stored in 9 different columns.
Each variable has different upper limits.
Is there a simpler way to write this code?
Each variable needs to be an even number.
Any "Rest___" variable goes from 8-20 (e.g. 8,10,...18,20)
Any "Work___" variable goes from 8-12 (e.g. 8,10,12)
Dim i As Long
Dim j As Long
Dim Rest1 As Integer
Dim Rest2 As Integer
Dim Rest3 As Integer
Dim Rest4 As Integer
Dim Work1 As Integer
Dim Work2 As Integer
Dim Work3 As Integer
Dim Work4 As Integer
Dim Work5 As Integer
Dim TableRange As Range
'I know the range should have at least 583,443 rows 583,443
Set TableRange = Range("b3:t1000")
i=1
j=1
For Rest1 = 8 To 20 Step 2
For Rest2 = 8 To 20 Step 2
For Rest3 = 8 To 20 Step 2
For Rest4 = 8 To 20 Step 2
For Work1 = 8 To 12 Step 2
For Work2 = 8 To 12 Step 2
For Work3 = 8 To 12 Step 2
For Work4 = 8 To 12 Step 2
For Work5 = 8 To 12 Step 2
TableRange(i, j) = Rest1
j = j + 1
TableRange(i, j) = Rest2
j = j + 1
TableRange(i, j) = Rest3
j = j + 1
TableRange(i, j) = Rest4
j = j + 1
TableRange(i, j) = Work1
j = j + 1
TableRange(i, j) = Work2
j = j + 1
TableRange(i, j) = Work3
j = j + 1
TableRange(i, j) = Work4
j = j + 1
TableRange(i, j) = Work5
j = 1
i = i + 1
Next Work5
Next Work4
Next Work3
Next Work2
Next Work1
Next Rest4
Next Rest3
Next Rest2
Next Rest1
As my code is, Excel throws a "Run-Time Error '6' Overflow"
I've included a picture of what the output should look like: SampleOutput