This is part of a code that copies a row range from a template sheet, to paste onto the active sheet, incrementing a number as it does.
Dim copySheet As Worksheet
Dim LRow As Long, i As Long
With pasteSheet
'~~> Find the last cell to write to
If Application.WorksheetFunction.CountA(.Cells) = 0 Then
'~~> Copy header row
copySheet.Rows(1).Copy .Rows(1)
LRow = 2
Else
LRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1
'~~> Find the previous number
For i = LRow To 1 Step -1
If .Cells(i, 2).Value2 = varString Then
StartNumber = .Cells(i, 6).Value2 + 1
Exit For
End If
Next i
End If
copySheet.Range("2:17").Copy .Rows(LRow)
What I am trying to do, rather than specify the row range ("2:17"), is to copy all rows until reaching a blank row.
I think I need to insert something like LRow = copySheet.Cells(Rows.Count, 1).End(xlUp).Row
after the Else
but my vba is poor and I really don't know.
How could I incorporate this into the above code?