1

I'm trying to copy the last row in one sheet (at a variable location) to the last row of data (at a variable location) in another sheet. So far I have tried This solution and This solution. They both copied a bunch of rows instead of the exact last row in the initial spreadsheet (WWData).

Sub copylastrow()
Dim Last_Row1 As Long
Dim Last_Row2 As Long
Last_Row1 = WWData.Cells(Rows.Count, 1).End(xlUp).Row
Last_Row2 = WWOutput.Cells(Rows.Count, 1).End(xlUp).Row + 1
WWData.Cells(Last_Row1).Copy WWOutput.Cells(Last_Row2)
End Sub

What am I doing wrong? Note: the WWData and WWOutput will have been previously defined.

Josh

Community
  • 1
  • 1
Josh M.
  • 27
  • 8
  • `Cells(Last_Row1).Copy` `cells` require 2 arguments: row and column. Also, qualify `Rows.Count` with the worksheet. – findwindow Jun 16 '16 at 15:25
  • 2
    Try changing `WWData.Cells(Last_Row1).Copy WWOutput.Cells(Last_Row2)` to `WWData.Rows(Last_Row1).Copy WWOutput.Rows(Last_Row2)` – Scott Craner Jun 16 '16 at 15:26
  • Both options worked great, thank you! Do either of you want to post these as an answer? – Josh M. Jun 16 '16 at 15:50
  • For any who stumble on this later I ended up using a combination of the two recommendations. I qualified my `Rows.Count` with the proper spreadsheet. I also replaced any `.Cells` with `.Rows`. A big thank you to the above posters for helping with this! – Josh M. Jun 16 '16 at 17:08
  • I think you can also post corrected Answer giving credit to scot and findwindow, in case they are unwilling from your side. This may benefit others in future for similar situation. – skkakkar Jun 17 '16 at 03:14

1 Answers1

0

For any who stumble on this later I ended up using a combination of the two recommendations. I qualified my Rows.Count with the proper spreadsheet. I also replaced the .Cells in the last line with .Rows.

End code looks like this:

Last_Row1 = WWData.Cells(WWData.Rows.Count, 1).End(xlUp).Row
Last_Row2 = WWOutput.Cells(WWOutput.Rows.Count, 1).End(xlUp).Row + 1
WWData.Rows(Last_Row1).Copy WWOutput.Rows(Last_Row2)  

A big thank you to @ScottCraner and @findwindow

Josh M.
  • 27
  • 8