wongsh
07-28-2016, 06:40 AM
Hi,
I am writing a program to check if the current row is the last row in the set of data.
Expected result should be if its not the last row, then select current row and all rows below and delete, and if it is the last row, then delete only this row. But it doesn't seem to be working this way, if its the last row, then all rows below are deleted (I have some populated cells apart from the main data set and those are deleted as well). Appreciate your advice! :)
ActiveCell.Offset(1, 0).Select
If Not IsEmpty(ActiveCell.Value) Then
ActiveCell.Offset(-1, 0).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Delete
Else
ActiveCell.Offset(-1, 0).Select
ActiveCell.EntireRow.Delete
End If
I am writing a program to check if the current row is the last row in the set of data.
Expected result should be if its not the last row, then select current row and all rows below and delete, and if it is the last row, then delete only this row. But it doesn't seem to be working this way, if its the last row, then all rows below are deleted (I have some populated cells apart from the main data set and those are deleted as well). Appreciate your advice! :)
ActiveCell.Offset(1, 0).Select
If Not IsEmpty(ActiveCell.Value) Then
ActiveCell.Offset(-1, 0).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Delete
Else
ActiveCell.Offset(-1, 0).Select
ActiveCell.EntireRow.Delete
End If