You can use the F5 key or a Form Control Button to run a macro to calculate operations within worksheets.
Step 1 – Generating a Macro for a Specific Task
- Go to the Developer tab > Visual Basic or ALT+F11 to open the Microsoft Visual Basic.
- Move to Insert > Module. The module window appears.
- Paste the following macro in the Module.
Sub RecalculateActivesheet()
ActiveSheet.Calculate
End Sub
Step 2 – Inserting and Modifying a Calculate Button
- Hover over the Developer tab.
- Click on Insert (in the Controls section).
- Select Button (Form Control).
- Draw the button as shown in the image.
- Drawing a calculate or Form Control Button takes you to the Assign Macro. Click OK in the Assign Macro window.
- Right click on the button. Select Edit Text from the Context Menu. Give a suitable name (i.e., Calculate) to the button.
- Right click on the button to apply Format Control.
- Choose desired Font, Font Style, Size, and Color form the Format Control, and click OK.
Step 3 – Assigning Macro to Calculate Button
- Right click on the button. Choose Assign Macro from the Context Menu.
- The Assign Macro window appears. Choose the existing inserted macro, and click OK.
Read More: How to Use VBA Code for Submit Button in Excel
Step 4 – Saving File as Macro Enabled Excel File Extension (.xlsm)
- Move to File > Save As.
- Select the File Type– Excel Macro-Enabled Workbook(*.xlsm).
- Click on Save.
Read More: VBA Code for Save Button in Excel
Step 5 – Testing Calculate Button
- Return to the worksheet and click on ReCalculate. Excel recalculates the formulas existing in the active worksheet.
Things to Remember
- You can use Shapes instead of Control Button.
- The F5 key works as an alternative to the button.
Download Excel Workbook
Related Articles
- Text Alignment with VBA Command Button in Excel
- How to Add Command Button Programmatically with Excel VBA
- How to Create a Stopwatch in Excel