View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Speeding up slow code

Carlos,
Eliminating dots speeds up code. That is especially helpful when
using loops as the effect is multiplied by the number of loops used.
If you can get a dot out of a loop do it.
Otherwise (not in a loop), I generally use a Range object or a With statement
if three or more dots can be replaced.

And from a post by Tushar Mehta, MS MVP, about 4 years ago...
'------------------
10,000 loops consisting of 4 statements, each setting the same variable
to a different range:
Time Rank
Set r = Range("$A$1", "$A$1") 0.090113 1
Set r = Range("A1", "A1") 0.1058 2

Set r = Range("$A$1") 0.177712 3
Set r = Range("A1") 0.180887 4
Set r = Cells(1, 1) 0.19815 5

Set r = Cells(1, "A") 0.308837 6
Set r = [A1] 0.621438 7

[The times are the average over 10 cycles and represent the time for
40,000 Set operations and one procedure call, since each test was in a
separate procedure.]
'------------------
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Carlos Nunes-Ueno"
wrote in message
Hi Jim,
Thanks for the reply and the link to the etiquette guide. I've been crazy
busy so I just finally got to check the group again. That and the news
server I had been using refused to show the post for days.

I tried your modified code (including changing the integers to longs) and it
definitely was faster. Running about 3300 rows took about two minutes this
time, and last time it would have been around five or so. I still wouldn't
cherish running 50,000 rows or anything like that but this is definitely an
improvement.
Just one more general question, is it usually faster to use a range object
than the .cells property of the worksheet for grabbing rows like this?

Thanks,
Carlos



"Jim Cone"
wrote in message
Try the code below.
I have added the rngRow variable (it eliminates some dots).
You should change the row variable declarations from Integer to Long.
I have no way of testing it so please provide some feedback.
Also, some helpful posting tips here...
http://www.cpearson.com/excel/newposte.htm