Speeding up VBA execution

%3CLINGO-SUB%20id%3D%22lingo-sub-1800412%22%20slang%3D%22en-US%22%3ESpeeding%20up%20VBA%20execution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1800412%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20attached%20excel%20sheet%2C%20i%20added%20the%20%22Composite%22%20and%20%22FloorData%22%20tabs%20to%20my%20excel%20sheet.%26nbsp%3B%20Those%20two%20tabs%20are%20not%20linked%20to%20other%20tabs%20in%20the%20sheet.%20When%20the%20tabs%20are%20in%20a%20separate%20excel%20sheet%2C%20the%20macro%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%22%20Click%20to%20Calculate%22%20runs%20in%26nbsp%3B%20a%20second%2C%20but%20when%20it%20is%20within%20this%20excel%20sheet%20it%20runs%20for%20nearly%20two%20minutes%20even%20though%20it%20is%20not%20linked%20to%20other%20tabs.%3C%2FP%3E%3CP%3E%22Composite%22%20tab%20password%3A%20chickenhawk%3C%2FP%3E%3CP%3EVBA%20password%3A%20csirocks%3C%2FP%3E%3CP%3Ein%20the%20%22Composite%22%20Tab%3A%3C%2FP%3E%3CP%3Ekey%20in%20in%20cell%20H27%3D%26nbsp%3B%202%3C%2FP%3E%3CP%3Ekey%20in%20in%20cell%20H28%3D%20150%3C%2FP%3E%3CP%3Ekey%20in%20in%20cell%20H29%3D%26nbsp%3B%208%3C%2FP%3E%3CP%3E%22Click%20to%20Calculate%22%20macro%20which%20is%20placed%20near%20cell%20G50.%20before%20you%20run%20it%20it%20is%20in%20light%20red%20then%20it%20turns%20green%20when%20it%20is%20done.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20don't%20know%20how%20to%20make%20the%20macro%20much%20faster.%20for%20some%20reason%20it%20slows%20down%20big%20time.%20Like%20i%20said%20earlier%20these%20two%20tabs%20are%20not%20linked%20to%20the%3C%2FP%3E%3CP%3EThank%20you%2C%3C%2FP%3E%3CP%3ESam%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1800412%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1801019%22%20slang%3D%22en-US%22%3ERe%3A%20Speeding%20up%20VBA%20execution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1801019%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F351459%22%20target%3D%22_blank%22%3E%40SamFares%3C%2FA%3E%2C%26nbsp%3B%3C%2FP%3E%3CP%3EExcel%20recalculates%20all%20your%20formulas%20(entire%20workbook)%20every%20time%20there's%20a%20change%20in%20a%20cell%20that%20affects%20a%20formula.%20You're%20workbook%20is%20fairly%20large%20so%20this%20probably%20explains%20why%20it%20takes%20so%20much%20time%20as%20opposed%20to%20when%20you%20separate%20your%20sheets%20to%20a%20different%20workbook.%20You%20can%20tweak%20this%20a%20bit%20by%20either%20disabling%20the%20automatic%20calculation%20or%20leaving%20it%20to%20automatic%20except%20for%20data%20tables.%20File%26gt%3BOptions%26gt%3BFormulas%26gt%3BCalculation%20options.%20Or%20leave%20your%20two%20sheets%20separated%20if%20they%20don't%20need%20to%20be%20in%20that%20workbook.%3C%2FP%3E%3CP%3ERead%20this%20for%20more%20details%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Fclient-developer%2Fexcel%2Fexcel-recalculation%23%3A~%3Atext%3DExcel%2520reevaluates%2520cells%2520that%2520contain%2CUse%2520them%2520sparingly%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Fclient-developer%2Fexcel%2Fexcel-recalculation%23%3A~%3Atext%3DExcel%2520reevaluates%2520cells%2520that%2520contain%2CUse%2520them%2520sparingly%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1801452%22%20slang%3D%22en-US%22%3ERe%3A%20Speeding%20up%20VBA%20execution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1801452%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F703724%22%20target%3D%22_blank%22%3E%40Bennadeau%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%26nbsp%3B%20Currently%20the%20edits%20in%20%22Composite%22%26nbsp%3B%20and%20running%20the%20macro%20does%20not%20affect%20the%20values%20in%20other%20tabs.%20so%20the%20results%20in%20this%20tab%20stay%20within%20this%20tab.%3C%2FP%3E%3CP%3E2.%20Ultimately%2C%20I'd%20like%20to%20connect%20this%20%22composite%22%20tab%20with%20others.%20What%20i%20don't%20get%20how%20calculation%20in%20other%20tabs%20affect%20the%20composite%20tab.%20No%20values%20are%20changed%20in%20other%20tabs.%3C%2FP%3E%3CP%3E3.%20I%20changed%20it%20to%20%22%3CSPAN%3Eautomatic%20except%20for%20data%20tables%22%20but%20it%20didn't%20make%20a%20difference.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E4.%20Would%20it%20be%20better%20to%20have%20them%20in%20two%20separate%26nbsp%3Bbooks%20and%20link%20them%3F%20would%26nbsp%3B%20linking%20two%20books%20slow%20the%20macro%20run%3F%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThank%20you!%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ESam%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1803256%22%20slang%3D%22en-US%22%3ERe%3A%20Speeding%20up%20VBA%20execution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1803256%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F351459%22%20target%3D%22_blank%22%3E%40SamFares%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20launched%20your%20workbook%20and%20you%20have%20a%20lot%20of%20formulas%20in%20there.%20Must%20have%20taken%20you%20a%20while%20to%20do%20this.%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20your%20questions%3A%3C%2FP%3E%3CP%3E1.%20As%20I%20said%2C%20if%20you%20change%201%20cell%20in%201%20tab%2C%20the%20entire%20workbook%20is%20recalculated.%3C%2FP%3E%3CP%3E2.%20Same%20as%20point%201%3C%2FP%3E%3CP%3E3.%20Have%20you%20tried%20manual%20calculation%3F%20After%20you%20run%20your%20macro%2C%20hit%20F9%20to%20recalculate%20the%20workbook%20if%20needed%3C%2FP%3E%3CP%3E4.%20Yes%20it%20would%20be%20better%20to%20keep%20them%20separately.%20At%20least%20in%20terms%20of%20performance.%20Linking%20them%20shouldn't%20affect%20the%20performance.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20this%20helps.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1803445%22%20slang%3D%22de-DE%22%3ESubject%3A%20Speeding%20up%20VBA%20execution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1803445%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F351459%22%20target%3D%22_blank%22%3E%40SamFares%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CSPAN%20class%3D%22%22%3EThis%20could%20help%20against%20this%3A%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CBR%20%2F%3E%3CSPAN%3EApplication.Calculation%20%3D%20xlCalculationManual%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Ebefore%20the%20start%20of%20the%20operation%20and%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CBR%20%2F%3E%3CSPAN%3EApplication.Calculation%20%3D%20xlCalculationAutomatic%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Eafter%20the%20operation%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20be%20happy%20to%20know%20if%20I%20could%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E*%20Kindly%20Mark%20and%20Vote%20this%20reply%20if%20it%20helps%20please%2C%20as%20it%20will%20be%20beneficial%20to%20more%20community%20members%20reading%20here.%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Hello,

 

In the attached excel sheet, i added the "Composite" and "FloorData" tabs to my excel sheet.  Those two tabs are not linked to other tabs in the sheet. When the tabs are in a separate excel sheet, the macro       " Click to Calculate" runs in  a second, but when it is within this excel sheet it runs for nearly two minutes even though it is not linked to other tabs.

"Composite" tab password: chickenhawk

VBA password: csirocks

in the "Composite" Tab:

key in in cell H27=  2

key in in cell H28= 150

key in in cell H29=  8

"Click to Calculate" macro which is placed near cell G50. before you run it it is in light red then it turns green when it is done.

 

I don't know how to make the macro much faster. for some reason it slows down big time. Like i said earlier these two tabs are not linked to the

Thank you,

Sam

7 Replies
Highlighted

Hi @SamFares

Excel recalculates all your formulas (entire workbook) every time there's a change in a cell that affects a formula. You're workbook is fairly large so this probably explains why it takes so much time as opposed to when you separate your sheets to a different workbook. You can tweak this a bit by either disabling the automatic calculation or leaving it to automatic except for data tables. File>Options>Formulas>Calculation options. Or leave your two sheets separated if they don't need to be in that workbook.

Read this for more details: https://docs.microsoft.com/en-us/office/client-developer/excel/excel-recalculation#:~:text=Excel%20r....

 

Highlighted

Hi @Bennadeau 

1.  Currently the edits in "Composite"  and running the macro does not affect the values in other tabs. so the results in this tab stay within this tab.

2. Ultimately, I'd like to connect this "composite" tab with others. What i don't get how calculation in other tabs affect the composite tab. No values are changed in other tabs.

3. I changed it to "automatic except for data tables" but it didn't make a difference.

4. Would it be better to have them in two separate books and link them? would  linking two books slow the macro run? 

 

Thank you!

Sam

 

Highlighted

@SamFares 

I launched your workbook and you have a lot of formulas in there. Must have taken you a while to do this. 

To your questions:

1. As I said, if you change 1 cell in 1 tab, the entire workbook is recalculated.

2. Same as point 1

3. Have you tried manual calculation? After you run your macro, hit F9 to recalculate the workbook if needed

4. Yes it would be better to keep them separately. At least in terms of performance. Linking them shouldn't affect the performance.

 

I hope this helps.

Highlighted

@SamFares 

 

This could help against this:


Application.Calculation = xlCalculationManual
before the start of the operation and


Application.Calculation = xlCalculationAutomatic
after the operation

 

I would be happy to know if I could help.

 

Nikolino

I know I don't know anything (Socrates)

 

* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here.

Highlighted

Hi @Nikolino 

 

I placed the code as shown below at the beginning and end. the values in other tabs will depend on the values in the "composite" tab where the macro is.  if i did what you suggested correctly, I didn't see a noticeable difference. 

Thanks,

Sam

 

SamFares_0-1603294433341.png

 

Highlighted

@SamFares 

Excuse me in advance, but at the moment I can't take the time to look at the whole workbook with the VB code (there are a lot of modules so far).
In spite of the test, here is a way to speed up VBA code.

With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With

'Dein Code

With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With

 

However, you have to weigh up which of these conditions may be necessary for the correct execution of your macro.

 

But I am almost certain that there will be a few more people who will / can offer you an even better solution.
My knowledge compared to some here is very modest (to put it mildly).

 

Sorry that I took your time and couldn't give you a quick solution.

 

Wish you a nice day.

Nikolino

I know I don't know anything (Socrates)

 

Highlighted

Thank you @Nikolino