learn microsoft excel

Calculations using macros in Microsoft Excel

Excel 2007 Excel 2003 Home Macros Excel 2003 Excel 2010
About Us Offline Training Excel Books

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 whcih you may be working. You can add, subtract, average, multiply or divide according to the needs of the sitauation. 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 code is given below:

Sub calculate()
Range("A4") = "Tom"
Range("B4") = 5000
Range("C4") = Range("B4") * 0.5
Range("D4") = Range("C4") + Range("B4")
End Sub

Watch the video below to see the implementation.




Reference
Excel 2007 Excel 2003 Macros Excel 2007 Macros Excel 2003 Excel 2010
About Us Offline Training Excel Books