LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How can I make this Loop faster, screen updating is off


You can often see a significant increase in performance by storing all
the rows to delete in a Range type variable and then delete that range
with one Delete operation. For example,

First, declare the variable in which the rows to be delete will be
referenced:

Dim DeleteThese As Range

Then, get rid of

Rows(r).Delete


and replace it with

If DeleteThese Is Nothing Then
Set DeleteThese = Rows(r)
Else
Set DeleteThese = Application.Union(DeleteThese, Rows(r))
End If

Finally, after the Next loop control statement, delete the range
DeleteThese with one single Delete.

DeleteThese.Delete

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Fri, 12 Dec 2008 02:42:36 -0800 (PST),
wrote:

LastRow = Range("F" & Rows.Count).End(xlUp).Row

For r = 2 To LastRow Step 1 ' Headings in row 1
If Cells(r, "F").Value = "Closed" Then
Rows(r).Copy Destination:=Sheets _
("Interim").Range("A2").Offset(off, 0)
Rows(r).Delete
off = off + 1
End If
Next




Thanks



 
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
Is there a faster way to loop thru cells Mike Excel Programming 7 April 10th 08 08:03 AM
For Next loop faster with counter after Next? RB Smissaert Excel Programming 22 August 28th 06 05:12 AM
Faster way to loop through two ranges YH Excel Programming 5 August 26th 06 05:17 PM
Is there a faster loop than this Andibevan Excel Programming 4 August 25th 06 03:27 PM
Faster For-Next Loop? [email protected] Excel Programming 3 January 7th 05 09:08 PM


All times are GMT +1. The time now is 09:54 AM.

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"