Link to home
Start Free TrialLog in
Avatar of mato01
mato01Flag for United States of America

asked on

Delete All Rows after Last Row with Data

I need to go to the last row with data, and delete all the rows after that row.  

Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Try a snippet like this:


Dim LastR As Long
With ActiveSheet
    LastR=.cells(.rows.count,1).end(xlUp).row
    .Range(lastr+1 & ":" & .rows.count).delete
End with
ASKER CERTIFIED SOLUTION
Avatar of Michael Fowler
Michael Fowler
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The above code suggestions would need to be modified, if Column A for some reason doesn't always have the last row of data.

Otherwise, perhaps UsedRange could be used to avoid that...

This should work:

With ActiveSheet
     .Range(.Cells(UsedRange.Rows.Count+1,1),.Cells(.Rows.Count,1)).EntireRow.Delete
End With

Dave
>>The above code suggestions would need to be modified, if Column A for some reason doesn't always have the last row of data.

The above was miss-stated.  Michael74's code would work just fine.

Dave