PC Review


Reply
Thread Tools Rate Thread

Delete empty rows with macro by John Walkenbach

 
 
Steve G
Guest
Posts: n/a
 
      2nd Aug 2007
I am trying to delete empty rows. I copied this macro from Mcrosoft
Excel 2000 Power Programming with VBA by John Walkenbach. I have
Excel 2003. The code below is identical to what is in the book except
for the two 'Dim' statements. The macro is one of 4 modules in my
personal.xls file. I get the following error message:

Run time error '91.' Object variable or with block variable not set.

Any help would be appreciated. Steve G


Sub DeleteEmptyRows()

Dim LastRow As Range
Dim r As Integer
LastRow = ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For r = LastRow To 1 Step -1
If Application.WorksheetFunction.CountA(Rows(r)) = 0 _
Then Rows(r).Delete
Next r
End Sub

 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      2nd Aug 2007

LastRow should be declared as a Long.
(same for r)
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"Steve G" <emailfromandtome-(E-Mail Removed)>
wrote in message I am trying to delete empty rows. I copied this macro from Mcrosoft
Excel 2000 Power Programming with VBA by John Walkenbach. I have
Excel 2003. The code below is identical to what is in the book except
for the two 'Dim' statements. The macro is one of 4 modules in my
personal.xls file. I get the following error message:

Run time error '91.' Object variable or with block variable not set.
Any help would be appreciated. Steve G

Sub DeleteEmptyRows()
Dim LastRow As Range
Dim r As Integer
LastRow = ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For r = LastRow To 1 Step -1
If Application.WorksheetFunction.CountA(Rows(r)) = 0 _
Then Rows(r).Delete
Next r
End Sub
 
Reply With Quote
 
Paul D. Simon
Guest
Posts: n/a
 
      3rd Aug 2007
Perhaps this will also help you. (You do have to highlight a range
first, though.)


Sub DeleteEmptyRows()
Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub


P.S.
My apologies if my reply appears twice. I can't seem to get me
replies to post to this Newsgroup anymore.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Empty Rows Macro Workbook Microsoft Excel Programming 2 13th Feb 2009 03:06 AM
Pls help: macro to delete empty rows curiousgeorge408@hotmail.com Microsoft Excel Programming 4 5th Feb 2009 05:04 PM
Delete Empty Rows Macro yepiknowiam Microsoft Excel Programming 6 22nd Aug 2008 10:53 PM
John Walkenbach Color Palette =?Utf-8?B?RXhjZWxNb25rZXk=?= Microsoft Excel Programming 0 14th Jul 2005 04:17 PM
How do I write a macro to delete all rows from the first empty ro. =?Utf-8?B?Sm9uIE0=?= Microsoft Excel Programming 2 12th May 2005 06:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:29 PM.