title: VBA - Write all possible combinations of 4 columns of data
body: <p>I've found script for writing all the possible combinations for 3 columns of data but am trying to modify the code to write 4 columns and possibly 5 and am not sure how. If anyone can help that would be great! I've tried doing what I think should work by adding in extra variables where they would follow (where I think they would go logically) but am geting a "Compile Error: Do without loop" that I cant explain.</p>
  
  <p>Here is the code for the 3 columns (without my modifications) from User Excellll.</p>
  
  <p>The description of the code is here:"This code will take the data from columns A, B, and C, and give the output you described in columns E, F, and G."</p>
  
  <pre><code>Sub combinations()
  
  Dim c1() As Variant
  Dim c2() As Variant
  Dim c3() As Variant
  Dim out() As Variant
  Dim j, k, l, m As Long
  
  
  Dim col1 As Range
  Dim col2 As Range
  Dim col3 As Range
  Dim out1 As Range
  
  
  Set col1 = Range("A1", Range("A1").End(xlDown))
  Set col2 = Range("B1", Range("B1").End(xlDown))
  Set col3 = Range("C1", Range("C1").End(xlDown))
  
  c1 = col1
  c2 = col2
  c3 = col3
  
  Set out1 = Range("E2", Range("G2").Offset(UBound(c1) * UBound(c2) * UBound(c3)))
  out = out1
  
  j = 1
  k = 1
  l = 1
  m = 1
  
  
  Do While j &lt;= UBound(c1)
      Do While k &lt;= UBound(c2)
          Do While l &lt;= UBound(c3)
              out(m, 1) = c1(j, 1)
              out(m, 2) = c2(k, 1)
              out(m, 3) = c3(l, 1)
              m = m + 1
              l = l + 1
          Loop
          l = 1
          k = k + 1
      Loop
      k = 1
      j = j + 1
  Loop
  
  
  out1.Value = out
  End Sub
  </code></pre>
  
  <p>Thanks in advance for your help</p>