title: Copy and Paste a dynamic range between two workbooks
body: <p>I am trying to copy and paste data found in one workbook to another. I am having difficulties copying the data and I am not too sure if it is the looping through the row data, which is causing the issues: </p>
  
  <pre><code>Sub essaie()
  
      Dim x As Workbook
      Dim y As Workbook
      Dim xlastcol As Integer 'variable for the last row
      Dim xcol As Variant 'variable first row
      Dim Headers() As Variant
      Dim h As Variant
      Dim ws As Worksheet
      Dim xrow As Integer
      Dim xlastrow As Variant
  
      Set y = Workbooks("VBAGOOD.xlsx")
      Set x = Workbooks("Aubaine.xlsm")
  
      Headers() = Array("net", "date", "description")
  
      y.Worksheets("try").Activate
  
      Set ws = y.Worksheets("try")
  
      xcol = 1 
      xlastcol = ws.Cells(2, ws.Columns.Count).End(xlToLeft).Column
  
      xrow = 2
      xlastrow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
  
      Do Until xcol = xlastcol 'loop through a range of data
      Do Until xrow = xlastrow
  
          For Each h In Headers
              If h = ws.Cells(xcol, xlastcol).Value Then
                  ws.Activate
                  ws.Cells(xrow, xlastrow).Select
                  Selection.Copy
                  x.Activate
                  x.Worksheets("test").Range("a1:a65").PasteSpecial
             End If  
          Next h
  
      Loop
      Loop
  
  End Sub
  </code></pre>
  
  <p>The data I am trying to copy is below three columns.</p>
  
  <pre><code>date      address     comments 
  
  123       udhsdh      gguu
  
  124       udhsdh      gguu
  
  125       udhsdh      sdg
  </code></pre>