Forum Discussion
djreyes
Jun 30, 2023Copper Contributor
VBA Macro
Hi,
Please let me know if I am missing something.
'Find the next available row in the destination sheet
nextRow = destinationSheet.Cells(destinationSheet.Rows.Count, 1).End(xlUp).Row + 1
Instead of going to the first row, its going to the second row.
Please see attached screencapture.
Thanks for the help!
5 Replies
If the entire column is still empty, destinationSheet.Cells(destinationSheet.Rows.Count, 1).End(xlUp).Row will be 1, so if you add 1 you end up with 2.
You could use
Dim rngLastCell As Range Set rngLastCell = destinationSheet.Cells(destinationSheet.Rows.Count, 1).End(xlUp) If rngLastCell.Value = "" Then nextRow = 1 Else nextRow = rngLastCell.Row + 1 End If
- djreyesCopper ContributorI tried and it didnt work, should I add it like this?
' Find the next available row in the destination sheet
Dim rngLastCell As Range
Set rngLastCell = destinationSheet.Cells(destinationSheet.Rows.Count, 1).End(xlUp)
If rngLastCell.Value = "" Then
nextRow = 1
Else
nextRow = rngLastCell.Row + 1
End IfThe code that I posted should replace the code that you included in the first post. How you use nextRow is up to you.
The code calculates nextRow correctly - I tested it. What is the problem you're having with it?