VBA Code taking progressively longer to execute

BetTheFarm

New Member
Joined
Jun 5, 2008
Messages
1
Hello,

I've got a relatively lengthy VBA Excel macro that accomplishes it's goal - mainly range manipulation. The problem is that each time I execute the macro, it takes about 5% longer than the time before (I thought it was my imagination, but I used a timer to verify).

Each time I run the macro, it is not adding more cells to the spreadsheet, just replacing them with identical formulas (i.e., a "refresh"). Is there a cache that is filling up? Can I reset it?

Interestingly, if I save and close the workbook, reopen and excecute the macro, it runs quickly again the first time and then becomes progressively slower.

I'm confused! Thanks for any advice you may have...
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I have been having a simlar problem. It seems to hinge on a column with
word-wrap.

Even though I preset the format to word-wrap, when I load the sheet,
excel obstinately ignores my formatting and resets it. So I have to re-apply the word-wrap after the cells are loaded.

The first time I open the book the frmatting is applied very quickly.

But when I refresh the sheet , I.e. Clear it and then reload, the formatting takes progressively longer.

I tried using Activesheet.usedrange in hopes that it would clear the memory, but it did not make any difference !!!
 
Upvote 0
Hello,

Try adding this to your code to see if it improves things:

Sub Test()
Application.ScreenUpdating = False
...macro code here
Application.ScreenUpdating = True
End Sub

You can also turn calculation to manual while the macro runs - that may speed things up as well. This is achieved as follows:

Sub Test()
Application.Calculation = xlManual
...macro code here
Application.Calculation = xlAutomatic
End Sub

Hope this helps.

Matty
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,923
Members
448,533
Latest member
thietbibeboiwasaco

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top