Excel VBA Code to Delete Last Row

Just a simple VBA question...

I need to find the last row in the active worksheet with data in any column and then delete that row.

What's the VBA script to do that?
Glenn StearnsAnalystAsked:
Who is Participating?
 
MWGainesJRCommented:
activesheet.Cells.End(xlDown).EntireRow.Delete
0
 
cyberkiwiCommented:
activesheet.usedrange.rows(activesheet.usedrange.rows.count).entirerow.delete
0
 
Glenn StearnsAnalystAuthor Commented:
Thanks!
0
 
MWGainesJRCommented:
kiwi, why are these not the same?

ActiveSheet.UsedRange.Cells.End(xlDown).Row
ActiveSheet.UsedRange.Rows.Count
I've never understood why?
0
 
cyberkiwiCommented:
If your sheet only has data in the range E5-J10,

ActiveSheet.UsedRange = E5-J10
ActiveSheet.UsedRange.Rows.Count = 6
ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count) << row 6 of the range, so E10-J10

ActiveSheet.UsedRange.Cells.End(xlDown).Row  '' don't know never used this, result is unpredictable

FWIW, the accepted answer is incorrect, try putting data in c2,c3,i7 and running it.

activesheet.Cells.End(xlDown).EntireRow.Select   << goes to last row in sheet, not data

I am not sure if the question should be reopened to rectify the error.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.