Question : [excel] - autofill speed?

I have a macro contains the following lines for autofilling:


    Range("D2:I2").AutoFill Destination:=Range("D2:I9"), Type:=xlFillDefault
    Range("D22:I22").AutoFill Destination:=Range("D22:I29"), Type:=xlFillDefault
    Range("D42:I42").AutoFill Destination:=Range("D42:I49"), Type:=xlFillDefault
    Range("D62:I62").AutoFill Destination:=Range("D62:I69"), Type:=xlFillDefault
    Range("D82:I82").AutoFill Destination:=Range("D82:I89"), Type:=xlFillDefault


The macro itself is in a loop of running around 1000 times.
The macro is basically like this, everytime, the D2:I2, D22:I22..etc data are changed, and then autofilled... and then the data changed again, and then autofilled again...

My question is, why does my macro run @ a very fast speed @ the beginning, however, after around 200 times, it slows down dramatically. Why is that??
my cpu is duron 1ghz.
excel 2000

any ideas why?? can i make it run consistently fast??
because the speeds that it slows down to is very pathetic.. it takes like several seconds to autofill few lines..



   

Answer : [excel] - autofill speed?

Hi,

Sorry it took a while.
I'm still looking at your sheets at the moment, but it's not an easy fix. To make things faster, you'll have to rebuild the code. It seems like your pretty experienced in using Excel, but a bit less in programming VBA?

Tip: keep the number of commands to be processed at a minimum. For eaxample, you have a loop iterating hundreds of time. Instead of setting the pplication.screenupdating.false inside this loop. place it outside.
Also byundt has a point with the references to the workbook (sheet and range objects). Worksheet functions often have nice functionality, but each reference to the worksheet, workbook, or any range takes time to process. And since you are iterating hundreds of times...

But all these optimizations will not shorten the running time as much as you want, since you are doing a lot of stuff. So best is to skip running on the worksheet at all and use the method byundt mentioned, namely by use of arrays.

Random Solutions  
 
programming4us programming4us