Originally posted by TGR
How would anyone have time to write all those if statements in a 2 hr comp? Now that I've seen a solution i understand a bit on how to do it. Thanks for the help!
If you use a recursive function, you don't have to write much code at all.

Here is a general solution that calculates all permutations for any number of inputs:

VB Code:
  1. Sub Permutations(s As String, Optional sleading As String)
  2.  ' Nucleus
  3.  Dim i          As Long
  4.  Dim a          As Variant
  5.  
  6.  a = Split(s, ",")
  7.  For i = 0 To UBound(a)
  8.     If UBound(a) > 1 Then
  9.         Permutations Right$(s, Len(s) - InStr(1, s, ",")), IIf(Len(sleading), sleading & "," & Left$(s, InStr(1, s, ",") - 1), Left$(s, InStr(1, s, ",") - 1))
  10.     Else
  11.         Debug.Print sleading & "," & s
  12.     End If
  13.    
  14.     s = Right$(s, Len(s) - InStr(1, s, ",")) & "," & Left$(s, InStr(1, s, ",") - 1)
  15.  Next
  16. End Sub

To use the function pass csv input values and the function does the rest. Output is to the debug window.

For example to calculate all permutations for 1 2 10?
VB Code:
  1. Call Permutations("1,2,10")