title: Find Last Row in DataSet Excel VBA
body: <p>I'm trying to get my data import to find the last row of my dataset and paste the row of data from SQL Server into the blank row at the end of the data set.</p>
  
  <p>This is my code I have, but when running the code it will import the data but always on the last row, not the next blank row after the last row</p>
  
  <pre><code>Sub RunImport()
  On Error GoTo Err:
  cnnstr = "Provider=SQLOLEDB; " &amp; _
              "Data Source=MyServer; " &amp; _
              "Initial Catalog=Mydb;" &amp; _
              "User ID=User;" &amp; _
              "Password=Pwd;" &amp; _
              "Trusted_Connection=No"
  Set cnn = New ADODB.Connection
  Application.ScreenUpdating = False
  cnn.Open cnnstr
  Set rs = New ADODB.Recordset
  sQRY = "SELECT * FROM MyTable"
  rs.CursorLocation = adUseClient
  rs.Open sQRY, cnn, adOpenDynamic, adLockOptimistic, adCmdText
  Application.ScreenUpdating = False
  Sheet1.Range("B5").Select
  Range(Selection, Selection.End(xlDown)).Select
  ActiveCell.Offset(1, 0).CopyFromRecordset rs
  rs.Close
  Set rs = Nothing
  cnn.Close
  Set cnn = Nothing
  Exit Sub
  Err:
  MsgBox "The following error has occured-" &amp; vbCrLf &amp; vbCrLf &amp; VBA.Error, vbCritical, "MySpreadsheet"
  MsgBox VBA.Err
  End Sub
  </code></pre>
  
  <p>I imagine that I have put something in wrong around </p>
  
  <pre><code>Sheet1.Range("B5").Select
  Range(Selection, Selection.End(xlDown)).Select
  ActiveCell.Offset(1, 0).CopyFromRecordset rs
  </code></pre>
  
  <p>What do I need to do to put it right?</p>