Calculation set to manual at beginning of code yet UDF tries to recalculate during code...

lmoseley7

Board Regular
Joined
Jul 9, 2013
Messages
151
I have a workbook where there is a formula that searches for "Grand Total", as would appear at the end of a range when you've applied a subtotal, and then it takes a number from one column and subtracts numbers from the same row in several other columns, with the hope being that in the end the result is a sum of 0. Basically we are ensuring that we have picked up all the pieces of a total. Previously the formula was an unruly combination of 9 VLOOKUP formulas. I wrote a User Defined Function to make the formula a little easier to understand and much shorter. The UDF works great normally.

When I automated the clearing out of the sheet's data, replacing it with new data and adding a subtotal, I noticed when stepping through the code that it was constantly trying to recalculate my UDF, which made the code run slow. I then added code to switch the calculation method to manual during the code run and then switch it back to automatic at the end. Now I find that the code still tries to recalculate the UDF after the subtotal is added, and although the formula appears to return the correct amount, I get an object defined error when the UDF is being calculated.

Alternatives:
I could remove the formulas at the beginning of the code and then add them back near the end.
I could add an apostrophe to the formulas to deactivate them and then remove it later.
I could figure out how to keep the function from trying to run until I'm finished making changes or figure out why it is breaking altogether.

I would post the UDF, but I really don't think that is the issue. It seems that adding the subtotal forces a recalculation to occur, but I'm not sure why it is failing because the formula returns the correct result, the only error is in VBA. The macro code has so much going on, I'm not sure how to easily pull out only those pieces that would be beneficial to review.

Does anyone know of any tricks to quickly disable a few formulas until a macro is finished running?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I'm not sure of the reason, but the easy work-out (which you mentioned) is to just clear the cell(s) that use the UDF, and then write the formula to the cell in the VBA macro that gets ran.

I'll stay subscribed to see if someone knows why the UDF keeps getting calculated.
 
Upvote 0

Forum statistics

Threads
1,215,048
Messages
6,122,862
Members
449,097
Latest member
dbomb1414

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