Quote Originally Posted by Bruce Fox
G'Day WH, how are ya.

Wouldn't the math be (in the example at least)
8x7x6x5x4x3x2x1 (being a range from 1-8)

So that something simple like A,B,C (an Array of 3 elements) yould yeild:

ABC
ACB
BAC
BCA
CAB
CBA

Is that theory correct (if so I have seen it posted here before)?
No, no, no. The idea is to get combinations, not permutations (if I'm using those words right). ABC is the same as ACB as far as I'm concerned. I have an array of numbers. I need to find the best combination of those numbers so that the some of the combination gets closest to a target value. The sum of A+B+C would be the same as the sum of A+C+B. So I need exclusive combinations. And I need every combination or every length. The array might have 8 numbers, but the best combination might consist of only two of those numbers, or only one, or all 8.

I think I'm getting close with the code below, but I'm not sure how to work in the array.

VB Code:
  1. Sub DooDah()
  2.  
  3.     For x = 1 To 3
  4.         Combo "", 0, x, 1, 4
  5.     Next x
  6.  
  7. End Sub
  8.  
  9. Sub Combo(sPrefix, lDepth, lLen, lMin, lMax)
  10.  
  11.     For i = lMin To lMax
  12.       If lDepth = (lLen - 1) Then
  13.         Debug.Print sPrefix & i
  14.       Else
  15.         Combo sPrefix & i, lDepth + 1, lLen, i + 1, lMax + 1
  16.       End If
  17.     Next i
  18.  
  19. End Sub