You are basically counting in base three, using "digits" like "[0,0,1]". Counting is easy.
(°v°)
Main Topics
Browse All TopicsHi Experts,
I need a loop that generates the following output...
1st:[0,0,1],[0,0,1],[0,0,1
2nd:[0,0,1],[0,0,1],[0,0,1
3rd:[0,0,1],[0,0,1],[0,0,1
4th:[0,0,1],[0,0,1],[0,0,1
5th......
There can only be one 1 inside each [], it has to be in position a, b or c.
Therefore i think 3^6 = 729 possible combinations.
And it makes sense that:
729th: [1,0,0],[1,0,0],[1,0,0],[1
Answers in VBA please!
Many thanks!
Jon
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: matthewspatrickPosted on 2009-11-04 at 15:08:42ID: 25745102
Hello jondanger,
This seems to be doing it...
Sub DoIt()
Dim x1 As Long, x2 As Long, x3 As Long, x4 As Long, x5 As Long, x6 As Long
Dim r As Long
Dim BigArr(1 To 6) As String
Dim SmArr(1 To 3) As String
Workbooks.Add
For x1 = 1 To 3
For x2 = 1 To 3
For x3 = 1 To 3
For x4 = 1 To 3
For x5 = 1 To 3
For x6 = 1 To 3
SmArr(1) = IIf(x1 = 1, 1, 0)
SmArr(2) = IIf(x1 = 2, 1, 0)
SmArr(3) = IIf(x1 = 3, 1, 0)
BigArr(1) = "[" & Join(SmArr, ",") & "]"
SmArr(1) = IIf(x2 = 1, 1, 0)
SmArr(2) = IIf(x2 = 2, 1, 0)
SmArr(3) = IIf(x2 = 3, 1, 0)
BigArr(2) = "[" & Join(SmArr, ",") & "]"
SmArr(1) = IIf(x3 = 1, 1, 0)
SmArr(2) = IIf(x3 = 2, 1, 0)
SmArr(3) = IIf(x3 = 3, 1, 0)
BigArr(3) = "[" & Join(SmArr, ",") & "]"
SmArr(1) = IIf(x4 = 1, 1, 0)
SmArr(2) = IIf(x4 = 2, 1, 0)
SmArr(3) = IIf(x4 = 3, 1, 0)
BigArr(4) = "[" & Join(SmArr, ",") & "]"
SmArr(1) = IIf(x5 = 1, 1, 0)
SmArr(2) = IIf(x5 = 2, 1, 0)
SmArr(3) = IIf(x5 = 3, 1, 0)
BigArr(5) = "[" & Join(SmArr, ",") & "]"
SmArr(1) = IIf(x6 = 1, 1, 0)
SmArr(2) = IIf(x6 = 2, 1, 0)
SmArr(3) = IIf(x6 = 3, 1, 0)
BigArr(6) = "[" & Join(SmArr, ",") & "]"
r = r + 1
Cells(r, 1) = Join(BigArr, ",")
Next
Next
Next
Next
Next
Next
MsgBox "Done"
End Sub
Regards,
Patrick