Forum Discussion
Macros suddenly run much slower
I noticed that excel 365 macros suddenly take much longer to run. Seems to be correlated with the latest update of excel done on february 3rd on my machine
- timfrewinCopper Contributor
I had this same problem. Something has clearly changed on MS's side. Some macros which used to take around 30 secs were taking anywhere from 20 mins to 2.5 hours. This was a sudden change early last week. However, we've found a fix. Once we disabled automatic formula recalculation during execution of the macro, everything went back to normal. If anything, faster than before.
At the beginning of each function:
Application.Calculation = xlCalculationManual
At the end of each function:
Application.Calculation = xlCalculationAutomatic
Or, a better way, if you want to preserve the user settings of automatic vs manual calculation following completion of the macro:
Sub x() lCalc = Application.Calculation With Application .Calculation = xlCalculationManual .ScreenUpdating = False .DisplayAlerts = False ''///your code here .Calculation = lCalc .ScreenUpdating = True .DisplayAlerts = True End With End Sub
(Credit to user royUK on https://www.ozgrid.com/ forum for that addition and code snippet)
- Steve_PigsoftCopper ContributorOlivierb61 Thanks for the suggestion which worked for you ( Application.Calculation = xlCalculationManual + At the end of each function: Application.Calculation = xlCalculationAutomatic). Unfortunately, this does not fix the problem for me. I tried it - There are problems elsewhere in MS's code for latest Excel 365 releases. Their code needs fixing. Still, glad to hear that your macros are now back to speed
- MaartenMeermanCopper ContributorDon't forget to add calculate to the code as needed in places if you change cells and need results to be used elsewhere before the macro finishes
- Massimo069Copper Contributor
i read this post and applied the solution to my macro, as result took less than 1 sec to execute despite 15-20 sec without the command described.
this is the place vhere i applied it:
at the beginning
Public Sub name_of_my_macro()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual...all the code
and at the end
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End SubThank you so much, you saved me
- Rowland74Copper Contributor
It's only taken 2 years but I finally found the issue for us. We have a very large workbook for production planning that we've been using for 15 years, and around early 2022 it slowed way down, and got worse and worse. It turns out in one of the worksheets, the conditional formatting rules had been duplicated 17,000+ times.
What's strange is that no macros run to change anything on that worksheet, although they do reference data from it. I looked at a Dec 2021 copy of the workbook and the worksheet only had the original dozen or so conditional formatting rules. I found a reference on another forum that the duplication of conditional formatting rules is a recent bug in Excel - it happens when deleting/copying worksheets within a workbook (even though for us the worksheet with the problem is never deleted or copied, although others are every week).
I was unable to delete the conditional formats from the worksheet using the GUI...Excel would just crash. I was able to do it with the following code. I adjusted the loop parameters to delete 5000 conditional formats each time I ran it, took about 30 minutes to do each 5000. But workbook macros are back to normal speed and don't seem to be duplicating now.
Sub Remove_New_Formatting() Dim i As Long Sheets("<worksheet name>").Activate With ActiveSheet.Cells.FormatConditions For i = .Count To 3 Step -1 .Item(i).Delete Next i End With End Sub
- felixvsCopper Contributor
We are having the same problem in my company.
If someone knows how to fix it please let us know.
- MichaelN1776Copper Contributor
I have the same problem.
I have a large spreadsheet with one macro that takes about 10 minutes to run. When I open the spreadsheet, Excel is using about 400MB of RAM. As the macro runs, the amount of RAM increases. When it's finished, Excel is using about 1,600MB of RAM. After that, every action is Excel spikes the CPU up to 100%.
Looks to me like a recent update introduced some sort of memory release issue.
- Steve_PigsoftCopper ContributorI have the same problem: Current Excel for Microsoft 365 (Win 10) is now slow running macros AND is also very slow to close after running macros. These same files and macros still run fine on Excel 2007 and Excel 2010 on alternative Win 10 PCs, and the same macros ran fine on the Excel 365 PC UNTIL recent updates of Microsoft 365 / Excel 365 on that PC.
- MichaelN1776Copper ContributorSolved the problem by reverting back to an earlier version of Excel.
https://support.microsoft.com/en-us/topic/how-to-revert-to-an-earlier-version-of-office-2bd5c457-a917-d57e-35a1-f709e3dda841- Andrew__MaynardCopper ContributorThis fix worked for me too
- BeeradleeCopper Contributor
I've run into the same issue. Macros that used to take ~5 minutes to complete now take hours. I've instrumented my code and it appears that the slowdown is primarily related to copying data between cells. Turning off autocalculation has not yielded improvement.
- felixvsCopper ContributorPlease check the comment from CliveW85 in the post below, this has solved the problem for many users:
https://techcommunity.microsoft.com/t5/excel/excel-macro-runs-painfully-slow/m-p/3180940/emcs_t/S2h8ZW1haWx8dG9waWNfc3Vic2NyaXB0aW9ufEtaUkRaNzhDWjVIRTZEfDMxODA5NDB8U1VCU0NSSVBUSU9OU3xoSw#M134966- Steve_PigsoftCopper Contributor
Thanks: To confirm, the fix for Slow macros/ Slow exit from Excel once slow macros with Excel 365 have run suggested...
(by @CliveW85 in Post: https://techcommunity.microsoft.com/t5/excel/excel-macro-runs-painfully-slow/m-p/3180940/emcs_t/S2h8... )
....did work for me 100% (as per my previous entry under that Topic, posted: Feb 17 2022 01:33 PM)
CliveW85’s fix that works is as follows:
To restore normal ‘at-speed’ Excel 365 macro running again, even with most current Windows 365 versions of Excel – ‘Add the directories of the Excel file(s) with the macro(s) within as Excel Trusted Locations’.
To do this:
From the Excel ribbon, follow this path:
Developer > Macro Security >Trusted Location(s) and then add those new trusted locations that contain your Excel files - e.g., for me: I added “V:\Datatree\ExcelData\WORK\” and its subdirectories.
((*) If the Developer function is not available in the top ribbon of your Excel 365, add it via Excel>Options>Customise Ribbon> then select Developer, OK.)
(To be certain of a fix, not only did I add the directories which contained the Excel files(s) that contained the macro(s) within, but also the directories for any locations where my macros accessed data from. e.g., for me - F:\Datatree\CLP Project\ and its subdirectories.).)
After these actions, macros then run at a good speed once more, and exiting from Excel after running the macros is restored to being swift, too.
It would seem that up until recent (2022) updates to Microsoft 365 (Excel 365), listing Trusted Locations within Excel>Developer was not an essential requirement for running Macros at a reasonable speed, and now it is.
- LukeKrellCopper Contributor
I found that disabling the Hardware Graphic Acceleration solved this problem for me. Olivierb61
- Patrick_T2400Copper Contributor
Olivierb61 I have experienced in similar situation. Prior to running Macro in Excel (2021 & Office 365), my 16G DDR4 RAM would more than suffice. After I have started running Macro (simple ones too), RAM usage suddenly spiked to 100%, and that caused my PC to run extremely slowly, which I was not expecting with a Ryzen 9 CPU & RTX306 GPU. So, I simply upgraded to 32G DDR4 RAM, and it did not help much, which is ridiculous. My MB can support up to 128G DDR4 RAM, but I am not going to spend a few hundred dollars to upgrade to 128G RAM, just so that I can run Excel Macro. I doubt the 128G RAM would help the situation anyways. MS should make it clear the size of RAM is needed to run Macro in Excel without slowing down PC speed.
- HAODKCopper ContributorWe have the same issue in my company, Waiting for a solution from MS Excel team
- Olivierb61Copper Contributor
Have you put the folder in the Trusted Location (Developper Tab -> Macro security) ?
- HAODKCopper ContributorThe VBA codes have been pretty much optimized. We try very much to optimize the macros for many users in the company. It suddenly became several times slower than before. I timed the macros to compare the speed. When I repeated running the macro several times, it took longer and longer time every time repeating the macro. 50sec, 60sec, 70sec...2 mins
- miguel_grajedaCopper Contributor
I had this very problem, where my 4-year-old Windows 10 laptop would process a macro I wrote in 2.5 minutes, vs. my new Windows 11 laptop taking 40+ minutes. The specs on my new laptop are much better, which left me baffled.
After not finding a solution online, I started to compare my Windows 10 Laptop settings with the Windows 11 and what I found was the Enable VBA macros (Not recommended; potentially dangerous code can run) were selected for my Windows 10 system but not 11, so after making my change, I went from a 40+ minute run time down to 5 or so minutes. Still not as good as my old Windows 10 laptop, but a lot better than 40+ minutes.
For those that are unsure where to find the setting navigate to the following:
File >> Options >> Trust Center Settings... >> Macro Settings >> Select the Enable VBA Macros (not recommended; potentially dangerous code can run) radio button >> OK >> OK
All Done!
- Patrick_T2400Copper Contributor
Sounds good. I hope this works.
Would enable this option put the security at risk?
Patrick
- miguel_grajedaCopper Contributor
If you're running your own macros, not really. It can be if you're running someone else's off the internet and don't understand what is running in your Excel. Also, scan attachments before downloading via email. Some of these can contain VBA.