PDA

View Full Version : [SOLVED] Determining number of rolls to delete



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

p45cal
07-28-2016, 07:41 AM
Selecting instead of deleting (change .Select to .Delete or .Clear or .ClearContents):
Sub blah()
If Not IsEmpty(ActiveCell.Value) Then 'if the active cell is empty, abort (saves deleting one row if the active cell is blank).
Do Until IsEmpty(ActiveCell.Offset(os + 1).Value)
os = os + 1
Loop
Range(ActiveCell, ActiveCell.Offset(os)).EntireRow.Select
End If
End Sub

wongsh
07-28-2016, 07:04 PM
Thanks for your help! But I have another problem here :(
Not sure could it be because the rows that I am deleting is from filtered data, so it seems to be affecting other parts of my program

wongsh
07-29-2016, 04:33 AM
Sorry my bad!! Its a bug in another part of my program! Your code works perfectly fine! Thanks so much for your help!!