Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Delete empty rows with macro by John Walkenbach

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Delete empty rows with macro by John Walkenbach


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"
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Delete empty rows with macro by John Walkenbach

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
John Walkenbach - Ensuring that Data Validation is Not Deleted al007 Excel Programming 5 November 17th 05 09:04 AM
to: John Walkenbach - Face ID add-in STEVE BELL Excel Programming 0 September 12th 05 07:12 PM
John Walkenbach Color Palette (Repost) ExcelMonkey Excel Programming 1 July 15th 05 02:50 PM
John Walkenbach Color Palette ExcelMonkey Excel Programming 0 July 14th 05 04:17 PM
John Walkenbach Colour Palette ExcelMonkey[_190_] Excel Programming 1 March 20th 05 07:23 PM


All times are GMT +1. The time now is 02:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"