Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / December 2006

Tip: Looking for answers? Try searching our database.

sub to delete rows is very slow

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RITCHI - 30 Dec 2006 18:10 GMT
Hi

I have quite a long procedure that conditionally formats a worksheet.
It calls a number of other procedures including the one below to delete
rows.
It works well for i=50 but beyond 500 is very slow.  I need to check
over 3000rows
Any advice on how to speed things up would be appreciated.

Sub DeleteRows()
'deletes rows where number of characters in cells in column 1 is 0,
from bottom upwards
Dim i As Integer
   Application.ScreenUpdating = False
   With ActiveSheet
       For i = 500 To 6 Step -1
           If Len(Cells(i, 1)) = 0 Then
               With Cells(i, 1).EntireRow
                   .Delete Shift:=xlUp
               End With
           End If
       Next
    End With
   Application.ScreenUpdating = True
End Sub

Ritchi
Don Guillett - 30 Dec 2006 18:18 GMT
may be quicker

lr=cells(rows.count,1).end(xlup).row
For i = lr To 6 Step -1
 If Len(Cells(i, 1)) = 0 Then rows(i).Delete
Next

Signature

Don Guillett
SalesAid Software
dguillett1@austin.rr.com

> Hi
>
[quoted text clipped - 23 lines]
>
> Ritchi
RITCHI - 30 Dec 2006 19:34 GMT
Thanks Don
Brilliant - I'm trying to figure out your code but this has solved the
problem.

Ritchi

> may be quicker
>
[quoted text clipped - 34 lines]
> >
> > Ritchi
Don Guillett - 30 Dec 2006 20:37 GMT
Aw shucks.

Signature

Don Guillett
SalesAid Software
dguillett1@austin.rr.com

> Thanks Don
> Brilliant - I'm trying to figure out your code but this has solved the
[quoted text clipped - 40 lines]
>> >
>> > Ritchi
Dave Peterson - 30 Dec 2006 18:25 GMT
Saved from a previous post:

Turning calculation to manual, hiding the pagebreaks, and changing to normal
view can increase the speed.

You may want to do something like:

Option Explicit
Sub testme()

   Dim CalcMode As Long
   Dim ViewMode As Long
   
   Application.ScreenUpdating = False
   
   CalcMode = Application.Calculation
   Application.Calculation = xlCalculationManual
   
   ViewMode = ActiveWindow.View
   ActiveWindow.View = xlNormalView
   
   ActiveSheet.DisplayPageBreaks = False
       
   'do the work
   
   'put things back to what they were
   Application.Calculation = CalcMode
   ActiveWindow.View = ViewMode
   
End Sub

> Hi
>
[quoted text clipped - 23 lines]
>
> Ritchi

Signature

Dave Peterson

Jim Cone - 30 Dec 2006 18:27 GMT
Also, turn of the display of page breaks at the start of the sub...
ActiveSheet.DisplayPageBreaks = False
Signature

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

"RITCHI" <dick@privica.com>
wrote in message
Hi
I have quite a long procedure that conditionally formats a worksheet.
It calls a number of other procedures including the one below to delete
rows.
It works well for i=50 but beyond 500 is very slow.  I need to check
over 3000rows
Any advice on how to speed things up would be appreciated.

Sub DeleteRows()
'deletes rows where number of characters in cells in column 1 is 0,
from bottom upwards
Dim i As Integer
   Application.ScreenUpdating = False
   With ActiveSheet
       For i = 500 To 6 Step -1
           If Len(Cells(i, 1)) = 0 Then
               With Cells(i, 1).EntireRow
                   .Delete Shift:=xlUp
               End With
           End If
       Next
    End With
   Application.ScreenUpdating = True
End Sub

Ritchi


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.