Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1310
  • Last Modified:

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?
0
Glenn Stearns
Asked:
Glenn Stearns
  • 2
  • 2
2 Solutions
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now