Basic VBA quick question

superskid

Board Regular
Joined
Aug 25, 2006
Messages
160
I have really only used macros via recording them, or recording them and editing the code.

I have a workbook that has one sheet that takes forever to calculate, and I only need to calculate it when I want it to. Problem is when I first open the workbook I can get stuck waiting for that sheet to calculate.

I want to enter the code:

sheet3.EnableCalculation=False

3 questions:

1.) Where do I enter it? Do I choose VBA then this workbook and then just type it there?

2.) If the sheet is named will sheet3 still work as the name for it?

3.) Any other suggestions?
</pre>
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Before someone answers, is there a way to not use sheet3, but the sheet name instead? In case I move the tabs around I don't want the sheets to get all messed up and have this set for the wrong tab,
 
Upvote 0
You can reference sheets either like this:
Code:
Sheets("Your Sheet Name")
or like this:
Code:
Sheets(3)
You will want to click the module in the Project Explorer on the left of the VBE (visual Basic Editor) YourWorksheetName(Sheet3).

You can enter the code in the VBE Module for Sheet3 like this:
Code:
[COLOR=#0000ff]Sub[/COLOR] DisableCalc()
EnableCalculation = [COLOR=#0000ff]False[/COLOR]
[COLOR=#0000ff]End Sub[/COLOR]

Just remember if you do not re-enable calculation it will stay off.

If you want an easier way to do this you can go to the Formulas Tab and Click on Calculation Options. Change to Manual. (To Update Sheet calculations hit F9)
 
Last edited:
Upvote 0
The reason I don't want to have it calculate on sheet 3 is that I have an excel add on that links to my accounting software. It gives me custom formulas that pull data from my software and it is VERY slow. However, if auto calculate is turned off I need to click on the addon bar at the top, choose my accounting software and then choose there fast recalculate sheet button.

I tried to record a macro of me doing this but it doesn't work. How can I create a macro to run this?
 
Upvote 0
Try running this sub procedure in the Sheet 3 module (By clicking the "Play" button or hitting F5 while your cursor is in the sub procedure):


Code:
[COLOR=#0000ff]Sub[/COLOR] DisableCalc()
EnableCalculation = [COLOR=#0000ff]False
[/COLOR][COLOR=#0000ff]End Sub[/COLOR]

Then do whatever you need to do with your accounting add-in


Then Run this sub procedure in the Sheet 3 module (By clicking the "Play" button or hitting F5 while your cursor is in the sub procedure):

Code:
[COLOR=#333333][COLOR=#0000ff]Sub[/COLOR] DisableCalc()
EnableCalculation = [/COLOR][COLOR=#0000ff]True
[/COLOR][COLOR=#0000ff]End Sub[/COLOR]
If this doesn't work then the Add-in may be changing auto-calculate on while you are using it. If this is the case you may not be able to get around Sheet 3 being on auto-calculate.
 
Upvote 0
Is there anyway for me to check if it is the add-on that is turning on auto-calc because when I open the sheet currently sheet 3 still starts updating; however, if I have my excel options set to manual calculation it doesn't? Doesn't make sense?
 
Upvote 0
Maybe you are looking for this setting instead?:
Code:
Application.Calculation = xlCalculationManual

Try using a combination of the following procedures:

1.Turn Calculation off, or to Manual or whatever your needs are
2. Test that it is indeed turned off.
3. Run Add-in
4. Test Calculation Values afterward (Then you know if the add-in turned it on).

Code:
[COLOR=#0000ff]Sub[/COLOR] SetManCalc()
    Application.Calculation = xlCalculationManual
[COLOR=#0000ff]End Sub[/COLOR]
Code:
[COLOR=#0000ff]Sub[/COLOR] SetAutoCalc()
    Application.Calculation = xlCalculationAutomatic
[COLOR=#0000ff]End Sub[/COLOR]
Code:
[COLOR=#0000ff]Sub[/COLOR] SetSemiAutoCalc()
    Application.Calculation = xlCalculationSemiautomatic
[COLOR=#0000ff]End Sub[/COLOR]
Code:
[COLOR=#0000ff]Sub [/COLOR]TestAppCalculatuon()

[COLOR=#0000ff]     If [/COLOR]Application.Calculation = xlCalculationManual [COLOR=#0000ff]Then[/COLOR]
         MsgBox "Manual Calculation is Enabled"
[COLOR=#0000ff]     ElseIf [/COLOR]Application.Calculation = xlCalculationAutomatic[COLOR=#0000ff] Then[/COLOR]
         MsgBox "Automatic Calculation is Enabled"
[COLOR=#0000ff]     ElseIf [/COLOR]Application.Calculation = xlCalculationSemiautomatic [COLOR=#0000ff]Then[/COLOR]
         MsgBox "SemiAutomatic Calculation is Enabled"
[COLOR=#0000ff]     End If[/COLOR][COLOR=#0000ff]
[/COLOR]
[COLOR=#0000ff]End Sub[/COLOR]
Code:
[COLOR=#0000ff]Sub[/COLOR] SetEnabCalcTrue()
    EnableCalculation = [COLOR=#0000ff]True[/COLOR]
[COLOR=#0000ff]End Sub[/COLOR]
Code:
[COLOR=#0000ff]Sub [/COLOR]SetEnabCalcFalse()
    EnableCalculation = [COLOR=#0000ff]False[/COLOR]
[COLOR=#0000ff]End Sub[/COLOR]
Code:
[COLOR=#0000ff]Sub[/COLOR] TestEnCalc()

   [COLOR=#0000ff] If [/COLOR]EnableCalculation = [COLOR=#0000ff]False Then[/COLOR]
        MsgBox "Calculation is set to False"
    [COLOR=#0000ff]ElseIf [/COLOR]EnableCalculation = [COLOR=#0000ff]True Then[/COLOR]
        MsgBox "Calculation is set to True"
[COLOR=#0000ff]    End If[/COLOR]

[COLOR=#0000ff]End Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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