title: Get data from excel worksheet and copy it into the active workbook
body: <p>I'm new to using VBA and have found the code below. It works fine but I need all the rows in the source file. How can I change the code so I'm not limited to using the row numbers as the will be differten every time.</p>
  
  <pre><code>Private Sub Import1_Click()
  ' Get customer workbook...
  Dim customerBook As Workbook
  Dim filter As String
  Dim caption As String
  Dim customerFilename As String
  Dim customerWorkbook As Workbook
  Dim targetWorkbook As Workbook
  
  ' make weak assumption that active workbook is the target
  Set targetWorkbook = Application.ActiveWorkbook
  
  ' get the customer workbook
  filter = "Text files (*.xlsx),*.xlsx"
  caption = "Please Select an input file "
  customerFilename = Application.GetOpenFilename(filter, , caption)
  
  Set customerWorkbook = Application.Workbooks.Open(customerFilename)
  
  ' assume range is A1 - G10 in sheet1
  ' copy data from customer to target workbook
  Dim targetSheet As Worksheet
  Set targetSheet = targetWorkbook.Worksheets(1)
  Dim sourceSheet As Worksheet
  Set sourceSheet = customerWorkbook.Worksheets(1)
  
  targetSheet.Range("A6", "G10").Value = sourceSheet.Range("A2", "G6").Value
  
  ' Close customer workbook
  customerWorkbook.Close
  
  End Sub
  </code></pre>