Generate a combination list of values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using Office 2003 and Windows XP;

Picture 3 columns of values from 167 to 212; each value incrementing by 3.
Thus:

167 167 167
170 170 170
173 173 173
176 176 176
179 179 179
....

See above, except that each column goes up to 212; this gives a spread or
range of 16 values in each column.

I need a macro that will generate a list of these values in every possible
combination with one another (16 * 16 * 16 = 4096 combinations - I think).

Anyone got a clue how to do this, or has someone out there got some VBA code
they can post?

Thanks so much in advance for your assistance.
 
Try the macro below.

HTH,
Bernie
MS Excel MVP

Sub TryNow()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim r As Long

r = 2

For i = 167 To 212 Step 3
For j = 167 To 212 Step 3
For k = 167 To 212 Step 3
Cells(r, 1).Value = i
Cells(r, 2).Value = j
Cells(r, 3).Value = k
r = r + 1
Next k
Next j
Next i

End Sub
 
I'm sure you don't know, but you've helped me out before and I always
appreciate your help.

Nice neat solution; I was making it so much more complex.

Thanks so much and have a great day.
 
It is hard to keep track of usernames that aren't real names (like XP), but I'm always glad to help,
and I'm always happy to hear that my suggestions worked, so thanks for the feedback.

Bernie
MS Excel MVP
 
Back
Top