Thread: Speed Question
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Speed Question

Generally speaking deleting rows is slow. To speed it up you are better off
to accumulate a large range object that encompasses all of the row you want
to delete and then do one large delete at the end (as opposed to potentially
thousands of one line deletes). Something like this...

dim rngToSearch as range
dim rng as range
dim rngFound as range

set rngToSearch = range("A2", cells(rows.count, "A"))
for each rng in rngToSearch
if rng.value 100 then
if rngFound is nothing then
set rngfound = rng
else
set rngFound = Union(rng, rngFound)
end if
end if
next rng

if rngFound is nothing then
msgbox "Nothin to delete"
else
rngFound.entirerow.delete
end if
--

HTH...

Jim Thomlinson


"shelfish" wrote:

I have a couple of macros that sort through db output and delete
unwanted information

Example:
Do while selection < ""
if selection 100 hours then
selection.entirerow.delete
else offset to next row
endif
loop

Two questions:

First, is there a faster way to do this, i.e. sort for greater than 100
and delete the results?

Second, on one sheet that only has three columns this runs very fast.
(28k rows in about 15 minutes) but on another sheet with about 35
columns it only does about 2 rows a second. What is causing such a vast
difference in speed? Is it the number of columns deleted during the
entirerow.delete line?

Thanks for the help.