?
Solved

Excel VBA Code to Delete Last Row

Posted on 2010-08-12
5
Medium Priority
?
1,090 Views
Last Modified: 2012-05-10
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
Comment
Question by:Glenn Stearns
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
MWGainesJR earned 252 total points
ID: 33423409
activesheet.Cells.End(xlDown).EntireRow.Delete
0
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 248 total points
ID: 33423410
activesheet.usedrange.rows(activesheet.usedrange.rows.count).entirerow.delete
0
 

Author Closing Comment

by:Glenn Stearns
ID: 33423477
Thanks!
0
 
LVL 13

Expert Comment

by:MWGainesJR
ID: 33423497
kiwi, why are these not the same?

ActiveSheet.UsedRange.Cells.End(xlDown).Row
ActiveSheet.UsedRange.Rows.Count
I've never understood why?
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33423759
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question