Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number Combinations

Status
Not open for further replies.

Kstater30

Technical User
Apr 11, 2006
9
US
I am trying to find code that will result in all the variations in any order of a group of numbers, for example, 1,2,3,4,5. The result of running the code would give me 1,2,3,4,5, 1,3,2,4,5, 1,4,2,3,5, etc. until running through all combinations without repeating. Would anyone be willing to help me?
 
A starting point (brute force method)
r = 0
For i = 1 To 5
For j = 1 To 5
For k = 1 To 5
For l = 1 To 5
For m = 1 To 5
If i <> j And i <> k And i <> l And i <> m _
And j <> k And j <> l And j <> m _
And k <> l And k <> m And l <> m Then
r = r + 1
Debug.Print r, i & j & k & l & m
End If
Next
Next
Next
Next
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top