Calculations using macros in Microsoft Excel
Once you access the Excel cells using the range or cells property, you can easily perform calculations using macros based on your knowledge of the domain, example finance, in which you may be working. You can add, subtract, average, multiply or divide according to the needs of the situation. Of course, you can use the Excel inbuilt functions or your own functions to perform different calculations. The main idea here is to automate the calculations and hide the formulas from prying eyes.
- Click on the developer tab
- Select Visual Basic from the Code group
- In the Microsoft Visual basic Window click on insert in the menu bar
- Select Module
- In the workspace enter the code using the range or cell property and apply an appropriate formula
- Click on ‘Run’ to view the result
Of course, using the cells or range property you could have also added the labels
The VBA code is given below:
Range(“A4”) = “Tom”
Range(“B4”) = 5000
Range(“C4”) = Range(“B4”) * 0.5
Range(“D4”) = Range(“C4”) + Range(“B4”)
Watch the video below to see the implementation.