Solved

Excel VBA Code to Delete Last Row

Posted on 2010-08-12
5
998 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 63 total points
ID: 33423409
activesheet.Cells.End(xlDown).EntireRow.Delete
0
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 62 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

705 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