Search code examples
excelvbaworksheet

Why sh.calculate does not calculate the formulas in worksheet "sh"?


This is what I want: User enters formulas in different cells. At this point nothing should be calculated. Then she/he runs the macro which calculates all formulas in those cells and the results are shown in those cells.

So: I set the calculation to manual. And defined my macro to call : sh.calculate. Where sh is the worksheet the user will be using.

Issue: even after running the macro those cells still show the formula and not the result of it. i.e. if a cell is: =2+2 ,after running the macro it still shows =2+2 instead of 4.

This is how I set it to manual calculation when the excel file is opened:

 Application.Calculation = xlCalculationManual

After user adds formulas to different cells in UserForm sheet, he/she runs this macro:

sub calcFormulas()
    dim sh as Worksheet
    Set sh= ThisWorkbook.Sheets("UserForm")
    sh.Calculate
End Sub

Solution

  • If the cell format is "Text", formulas entered are not executed but treated as plain text. Change the cell format to e.g. "Standard" and check the results.