Any thoughts - VBA Slow Down with Range.Clear Command
Hi,
I use some Excel VBA code repeatedly to extract data from text files, then
to paste into new Excel workbooks, created from a template.
Now the code has worked successfully in the past, and for my current
application is taking 45 seconds to run.
In order to make my code more robust, I have added one line of code that
clears the contents of the template worksheet, before I paste in the new
data. In this way, I don't need to worry whether the previous template
"dummy" data has been overwritten.
The line of code is thus:-
Worksheets("Loads").Range("A1:H65536").Clear
Nothing too fancy you might think! However, this one extra line of code has
meant the code now takes 5 minutes to run, as opposed to 45 seconds.
Any thoughts anybody?
(I have noticed this kind of slow-down in the past: if for example I write
data to the template, then copy and paste it into the new workbook, there is
no slowdown. If I create the workbook, then write data directly to the
workbook, it takes exponentially longer.)
Thanks in advance for any thoughts,
Paul.
p.s. It is nothiong obvious like I have nested the Clear command within the
extraction loops; it is standalone, before any loops, and right after I have
created the new workbook from the template.
|