slow after running macro

Copper Contributor

I run a macro in excel using VB.  It runs extremely slow.  Once the program ends, the workbook is very slow to respond in normal worksheet movements.  if I close the program and reopen, it responds normally.

12 Replies

Hi Bruce,

 

We need to see this macro to figure out what the problem is.

Please copy the macro code here in a reply.

It would be better if you can attach the workbook itself.

 

Regards

Hi Haytham,

 

Thanks for taking the time to look at it. 

 

I have attached a copy of the workbook (I have put random names in the name column, but that does not affect the macro).  I am not a sophisticated programmer and don’t know all the shortcuts in coding, but the macro does what I want it to do, it just takes too much time, and once it exits, the workbook is slow to navigate until I close it and reopen it.

 

The macro does two basic procedures:

 

  1. it compares the raw data from golfers scores, computes the senior handicaps and compares it to the course handicap

 

  1. it takes the individual raw data, sorts by name, and prepares a printable version for each player. 

 

If you see a fix, just send me a copy to the revised macro with any comments you want to make.

 

 

Thanks,

Bruce

Hi Bruce,

 

Sorry on the late reply!

The macro performs a very long operation, and includes several For Loops statements, this is why it takes too much time!

 

Another reason, there are too many Conditional Formatting rules in the worksheet!

 

However, I've updated the macro to speed up the operation, please test it in the attached file.

 

Also, please review Conditional Formatting rules in the worksheet and see if you really need them all.

 

Regards

Hi Haytham,

 

Thanks so much.  It runs much faster.  I saw you added some code at the front of my macro - one of which doesn't allow the macro to update the screen which I could see takes a huge amount of time.  I'm not sure what the others do, but if you could point me to where I could find out, I'd appreciate it.  I need the conditional formatting so it is easy for the other golfers to visually see how they are doing and what holes they need to work on.

 

You have been a big help!

 

Bruce 

Thank you!

 

The idea behind these codes is to turn off everything that may lead to slow down the macro and not necessary for its operation.

 

In fact, this is the first time I use these codes in separate Subs and then call it inside the main Sub.

I took this idea from this site, please check it out to see the full explanation of these codes.

 

Regards

@Haytham Amairah 

 

Good morning, I am having the same issue.  I am not a coder.  I grabbed a code off the internet that would allow me to sum by color.  Now the xlsm file is running extremely slow.  I've attached a copy of the excel.  Can you help me?

@TAntolik 

 

Mostly, I would say it is due to the fact that you are passing entire columns (1 million+ cells) to the function to loop through.

 

I changed the functions to restrict the range it looks at to the used range, but sometimes the worksheet's used range needs to be reset so you may need to check/reset it if you notice it bogging down again. Or, just pass your actual range to the function instead of the entire column.

 

https://support.microsoft.com/en-us/office/locate-and-reset-the-last-cell-on-a-worksheet-c9e468a8-0f...

@JMB17 

 

Good morning, and Thank you so much!

 

I was wondering, typically we have multiple sheets in our workbook but I only want the macro to run on one of the sheets.  Am I able to assign this macro to only run on one sheet rather than the many sheets we may have in a workbook?

From what I see, it should only be running on the range that is given to it.
Hi all
I don't know if this thread is still open but in the last week 2, when a long macro that I run to simulate football matches finishes, Excel becomes very slow; when I type, it takes about a minute or two to be able to do so. When I restart Excel, it all works fine. Similar to the original post.

Strange thing is, I ran the same macro from a backup file from 2 years ago and same problem occurs, whereas back then, it would complete fine. The only things that have changed for me are Windows 11.

I use the same techniques such as disabling conditional formatting and screen updating, so not sure what else I should be optimising something that wasn't broken before. Is there some sort of caching that Excel builds up when it runs macro and can only be cleared after a restart?
There are some other users that have experienced the same thing. It appears it could be due to a recent update/patch Microsoft pushed:

https://techcommunity.microsoft.com/t5/excel/macros-suddenly-run-much-slower/m-p/3136265

https://techcommunity.microsoft.com/t5/excel/excel-macro-runs-painfully-slow/m-p/3180940/emcs_t/S2h8...

One of the commenters, in the second link, believes it may be related to 'trusted locations' and was able to improve performance by adding the directory in which the workbook was located to trusted locations.

I and other users in my organization have recently experienced the same thing (file with auto open macro takes eternity to open), but moving the file to the machines local D drive fixed it (and it's not a network speed issue). So, whatever MS did, it appears to be related to the file's location.
I did suspect that, glad I'm not the only one.

Thanks v much for the links, I'll review at my next opportunity