VBA - Advice on How to turn off or on excel calculation with status in a cell

VBA learner ITG

Active Member
Joined
Apr 18, 2017
Messages
267
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi all,

I wonder if I could get your advice if possible to perform the below requirement.

The below code is assigned to a shape within excel which basically turns off or on excel formula calculations when the button is clicked.

VBA Code:
Sub btn_autocalc_Click()
If Application.Calculation = xlManual Then
    Application.Calculation = xlAutomatic
    'btn_autocalc.Caption = "TURN FORMULAS OFF MACRO"
Else
   Application.Calculation = xlManual
   'btn_autocalc.Caption = "TURN FORMULAS ON MACRO"
End If
End Sub

But I want to have in a cell below the macro button as a text value to is to show the current status.

For example Text: "Formulas are currently turned off" or "Formulas are currently turned on"

I have tried adding this additional function into my workbook which works by showing if the formulas are on but i cannot get it to show as off if it is off.

Code:
Function CalculationMode() As String

    Dim cMode As XlCalculation

    Application.Volatile

    cMode = Application.Calculation

    Select Case cMode

    Case xlCalculationAutomatic: CalculationMode = "Auto"

    Case xlCalculationManual: CalculationMode = "Manual"

    Case xlCalculationSemiautomatic: CalculationMode = "Semi-Auto"

    End Select

End Function

And in a cell =CalculationMode()


Any advice appreicatated.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If you run this little macro, it will show you what values you need to check for the Application.Calculation property:
VBA Code:
Sub TestCalcModes()

    Application.Calculation = xlCalculationAutomatic
    MsgBox "Code for Automatic: " & Application.Calculation

    Application.Calculation = xlCalculationManual
    MsgBox "Code for Manual: " & Application.Calculation
    
    Application.Calculation = xlCalculationSemiautomatic
    MsgBox "Code for Semiautomatic: " & Application.Calculation
    
End Sub
 
Upvote 0
If you run this little macro, it will show you what values you need to check for the Application.Calculation property:
VBA Code:
Sub TestCalcModes()

    Application.Calculation = xlCalculationAutomatic
    MsgBox "Code for Automatic: " & Application.Calculation

    Application.Calculation = xlCalculationManual
    MsgBox "Code for Manual: " & Application.Calculation
   
    Application.Calculation = xlCalculationSemiautomatic
    MsgBox "Code for Semiautomatic: " & Application.Calculation
   
End Sub


Thank you for your time and this code.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,008
Members
448,935
Latest member
ijat

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