title: Loop through different ranges with variable bounds
body: <p>So I'm trying to copy different columns up to the last row used and just loop through every range I'm trying to access. For this I declared an array that stores the first half of the range (fixed) and add the last row with <em>&amp; LastRow</em> within the Range() but I always get an error <strong>Run-time error 9 Subscript out of range</strong> when looping through these ranges (the first row of the loop is marked). I just don't get why this isn't working (storing the <em>&amp; LastRow</em> in the array doesn't work either). I need this LastRow to be variable since it's going to change in the later section of the macro.</p>
  <pre><code>Sub ImportRows()
  
  Dim wbk As Workbook
  Dim LastRow As Long
  Dim CopiedColumns As Variant
  Dim InsertColumns As Variant
  Dim i As Integer
  
  Set wbk = ActiveWorkbook
  CopiedColumns = Array(&quot;A2:A&quot;, &quot;C2:C&quot;, &quot;F2:F&quot;, &quot;J2:J&quot;, &quot;L2:L&quot;)
  
  'Copy Paste
  '###########################################
  
  InsertColumns = Array(&quot;A2:A&quot;, &quot;B2:B&quot;, &quot;C2:C&quot;, &quot;D2:D&quot;, &quot;E2:E&quot;)
  With wbk.Worksheets(&quot;RawData&quot;)
      LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
  End With
  
  For i = 1 To 5
      wbk.Worksheets(&quot;RawData&quot;).Range(CopiedColumns(i) &amp; LastRow).Copy
      wbk.Worksheets(&quot;Comparrisson&quot;).Range(InsertColumns(i) &amp; LastRow).Insert
  Next i
  End Sub
  </code></pre>
  <p>Thanks for literally any help!</p>