title: VBA permutations of undetermined number of variables
body: <p>Recently I am trying to get the permutation of undetermined number of variables. For undetermined I mean I was aiming to create an input box for users to put in the number. </p>
  
  <p>Start from simple. Originally I was aiming to get a 4 digits permutations with each digit have different number of variables, i.e. 1st digit can only be A,B,C,D; 2nd digit be E,F; 3rd digit be G, H etc. Code are below:</p>
  
  <pre><code>Sub Permut()
  
  Count = 1
  
  For a = 1 To 4
  For b = 1 To 2
  For c = 1 To 2
  For d = 1 To 2
  For e = 1 To 2
  'chr(97) is the alphabet "a"
  Cells(Count, 1) = Chr(96 + a) &amp; Chr(96 + Len(a) + b) &amp; Chr(96 + Len(a) + Len(b) + c) &amp; _
               Chr(96 + Len(a) + Len(b) + Len(c) + d) &amp; Chr(96 + Len(a) + Len(b) + Len(c) + Len(d) + e)
  Count = Count + 1
  Next
  Next
  Next
  Next
  Next
  
  End Sub
  </code></pre>
  
  <p>This will give you 64 different combinations without repetition. </p>
  
  <p>Just wondering is there a way to generalize this process so that people can choose how many variables in total as well as within each digit?</p>
  
  <p>Thank you.</p>