I have written vba for a macro which loops through a data extract, looks if a row contains a value in a certain column and if so, then performs some data copy/move functions. This is to loop until the end of the rows of data in the file.
Everything works well except the last row of data if it contains data in the requisite column, doesn't trigger the actions. It's fixed if I re-run the macro. But ideally it would complete property in one run. Given I am setting finalrow at the beginning and then inserting rows, I am guessing this is causing the last row to be missed. But I added an incremental +1 to finalrow within the loop which seemed to work for all rows except last. Not sure why. Any help appreciated (i've removed code not critical to the issue):
Dim finalrow As Integer 'final row of data available
Dim ws As Worksheet ' worksheet
Set ws = ThisWorkbook.Worksheets("Axis_Inv_Data")
ws.Activate
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To finalrow
'1 find row with km
If IsEmpty(ws.Cells(i, 9)) = False Then
'2 insert row after for kms
Rows(i + 1).Insert
'3 move km data to new row
'4 copy shift data to new km row
' add one more row to total to ensure we don't miss last row
finalrow = finalrow + 1
End If
Next i
End Sub
Bookmarks