title: Excel VBA - Column count using variants
body: <p>I have searched the forums but I am really struggling to get part of my code to work. Basically the idea is to search sheet 1 and copy one or more columns depending on the criteria to a specific worksheet.
  i.e. if sheet 1 columns 1 and 3 contain "copy 01" then copy both columns to a sheet 2 and if  sheet 1 columns 2 and 4 contain "copy 02" then copy both columns to a sheet 3 etc.</p>
  
  <p>I can count rows fine using the code, but can't count columns. Seems to relate to not fiding the column range but I have no ideas to fix this! Any help would be much appreciated.</p>
  
  <pre><code> 'Row    
  Dim NR As Long
  Dim d As Variant
  
  d = ws1.Range("A1:A" &amp; Cells(Rows.Count, "A").End(xlUp).Row).Value
     For NR = 1 To UBound(d, 1)
  
  'column
  Dim NC As Long
  Dim e As Variant
  
  e = ws1.Range(Cells(1, Columns.Count).End(xlToLeft).Column).Value 
      For NC = 1 To UBound(e, 1)
  </code></pre>
  
  <p>Thanks,
  Stewart</p>