VBA to Turn on or off auto calculate

APML

Board Regular
Joined
Sep 10, 2021
Messages
216
Office Version
  1. 365
Hi All, I'm not so good at VBA. I have a sheet with multiple tabs and lots of calculations. I've found it necessary to switch off and on auto-calculation on some tabs so the sheet can perform better. The 1st code below works fine but I'm hoping to use the same macro to turn off and on auto calculate on another TAB at the same time. My modified code isn't doing it. Would appreciate all advice. FYI the worksheets are called ASX_Data and Analysis

SO THIS WORKS WITH 1 SHEEET IN THE WORKBOOK
Sub TurnOff()
Worksheets("ASX_Data").EnableCalculation = False

MsgBox ("AutoCalc Is OFF")
End Sub

Sub TurnOn()
Worksheets("ASX_Data").EnableCalculation = True

MsgBox ("AutoCalc Is ON")

End Sub




THIS DOESN'T WORK

Sub TurnOff()
Worksheets("ASX_Data, Analysis").EnableCalculation = False

MsgBox ("AutoCalc Is OFF")
End Sub

Sub TurnOn()
Worksheets("ASX_Data,Analysis").EnableCalculation = True

MsgBox ("AutoCalc Is ON")

End Sub
 

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,)
Separate lines of code for each sheet ;)
Example:
VBA Code:
Sub TurnOff()
    Worksheets("ASX_Data").EnableCalculation = False
    Worksheets("Analysis").EnableCalculation = False
'
    MsgBox ("AutoCalc Is OFF")
End Sub
 
Upvote 0
Solution
Thx, works well. Really appreciate the help
Glad to help.
just wonder, can you suggest a way that i'd quickly know that the auto-calculate is of (or on) on the sheet.
was thinking along the lines that I could conditional formal a cell to change color (or something) if the auto cal was off, not really sure..
but would be handy if I had a quick way to glance at the sheet and know the setting ...
 
Upvote 0
To check via vba code:

VBA Code:
Sub CheckAutocalculationMode()
'
    Application.Calculation = xlCalculationManual   ' (-4135)
'
    If Application.Calculation = -4135 Then
        MsgBox "Application.Calculation is set to Manual"
    End If
'

'
    Application.Calculation = xlCalculationAutomatic ' (-4105)
    If Application.Calculation = -4105 Then
        MsgBox "Application.Calculation is set to Automatic"
    End If
End Sub

See if that helps you.
 
Upvote 0
To check via vba code:

VBA Code:
Sub CheckAutocalculationMode()
'
    Application.Calculation = xlCalculationManual   ' (-4135)
'
    If Application.Calculation = -4135 Then
        MsgBox "Application.Calculation is set to Manual"
    End If
'

'
    Application.Calculation = xlCalculationAutomatic ' (-4105)
    If Application.Calculation = -4105 Then
        MsgBox "Application.Calculation is set to Automatic"
    End If
End Sub

See if that helps you.
Thx.. i'm not so good at vba, so not sure what to do with this?... can this some how trigger a conditional format and change color a a cell
 
Upvote 0

Forum statistics

Threads
1,214,792
Messages
6,121,612
Members
449,038
Latest member
apwr

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