Computing.Net > Forums > Programming > EXCEL MACRO FOR DELETING BLANK ROWS PROB

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

EXCEL MACRO FOR DELETING BLANK ROWS PROB

Reply to Message Icon

Name: Walt
Date: July 18, 2002 at 21:38:06 Pacific
Comment:

I am trying to use the following macro to get rid of some blank rows:

Range("A1").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete

The problem is that I must do this on a column of data that was pasted from another worksheet using Edit, Paste Special, Values only. Although the blank cells do not have any data or formulas in them Excel is not recognizing them as blank and the macro cannot delete the associated rows.

I tested this using the Edit, Goto, Special command choosing the Blanks selection. That action does not select the empty cells in the column, just those around the pasted cells.

Can anyone help me with this bugger so that the macro will work the way it should? Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: A Certain TH
Date: July 19, 2002 at 00:43:42 Pacific
Reply:

Hi Walt

I think your problem is in the line:
Range("A1").Select

You should redefine the area that has been pasted into, and THEN perform the rest of your macro. For example:

If you know that the pasted values are always in the first column, then use:

Range("A:A").Select
or
Columns(1).Select

of course, as I always say, I LOVE one-liners, so you could always forget the "select" business and try:

Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete

as one line (which just doesn't fit on this page).

DON'T FORGET: When you define the range within which to expose the blank cells, if the ranges overlap you will get an error (which is why the 'select a whole column' method usually gets my vote - Nb. It will only look within a used range, so its not going to go checking 65535 rows of data every time, so no real speed issues)

Hope that answers your problem.

Tom


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: EXCEL MACRO FOR DELETING BLANK ROWS PROB

how to create exce macro for Busine www.computing.net/answers/programming/how-to-create-exce-macro-for-busine/3338.html

deleting rows from Excel with Macro www.computing.net/answers/programming/deleting-rows-from-excel-with-macro/17077.html

Excel Macro Delete Record www.computing.net/answers/programming/excel-macro-delete-record/11148.html