title: Excel vba Create combinations in same row each one
body: <p><br>
  I need help with a macro that exports all combinations of a range in same row each one ( I mean horizontal exports).</p>
  
  <p>Every combination I want to be in one cell each time.</p>
  
  <p>I want to change any time the number of strings in the range and also the number of strings combinations (In the example below 4 strings in the range and 3 for combinations) </p>
  
  <pre><code>1. A B  C  D     -------------ABC --ABD--ACD--BCD
   2. E F  G  H--------------EFG---EFH--EGH--FGH
   3. I G  K  L----------------IGK----IGL---IKL---GKL
  </code></pre>
  
  <p>Below its a module that I found in web that is very close to what I need.</p>
  
  <p>I am very new to Vba macros and I cannot achieve what I am looking for with the below code  </p>
  
  <pre><code>Private NextRow As Long
  
  Sub Test()
  Dim V() As Variant, SetSize As Integer, i As Integer
  
      SetSize = Cells(2, Columns.count).End(xlToLeft).Column
      ReDim V(1 To SetSize)
  
      For i = 1 To SetSize
          V(i) = Cells(2, i).Value
      Next i
  
      NextRow = 4
      CreateCombinations V, 3, 3
  
  End Sub
  
  
  Sub CreateCombinations( _
                     OriginalSet() As Variant, _
                    MinSubset As Integer, MaxSubset As Integer)
  
  Dim SubSet() As Variant, SubSetIndex As Long
  Dim SubSetCount As Integer, Bit As Integer
  Dim k As Integer, hBit As Integer
  Dim MaxIndex As Long
  
  hBit = UBound(OriginalSet) - 1
  ReDim SubSet(1 To UBound(OriginalSet))
  
      MaxIndex = 2 ^ UBound(OriginalSet) - 1
      For SubSetIndex = 1 To MaxIndex
          SubSetCount = BitCount(SubSetIndex)
          If SubSetCount &gt;= MinSubset And SubSetCount &lt;= MaxSubset Then
              k = 1
              For Bit = 0 To hBit
                  If 2 ^ Bit And SubSetIndex Then
                      SubSet(k) = OriginalSet(Bit + 1)
                      k = k + 1
                  End If
              Next Bit
              DoSomethingWith SubSet, SubSetCount
          End If
      Next SubSetIndex
  End Sub
  
  
  Sub DoSomethingWith(SubSet() As Variant, ItemCount As Integer)
  Dim i As Integer
  
  
      For i = 1 To ItemCount
          Cells(NextRow, i) = SubSet(i)
      Next i
      NextRow = NextRow + 1
  End Sub
  
  
  
  
  
  Function BitCount(ByVal Pattern As Long) As Integer
      BitCount = 0
      While Pattern
          If Pattern And 1 Then BitCount = BitCount + 1
          Pattern = Int(Pattern / 2)
      Wend
  End Function
  </code></pre>