The main aim of
training video is to make you familiar with the syntax writing a
formula in an Excel macro.
- Open a new Excel worksheet
- Click on Tools in the menu bar, select Macro and from
drop down menu select Visual Basic Editor
- In the Visual Basic Editor window, click on Insert
- In the workspace type sub and follow it with an
macro name like 'calculation'
- The 'End Sub' line is added automatically by the
Basic Editor in Excel
- Between the above lines write your Excel macro code
data into specified cells as shown in the training video
- Range("A1"), for example, accesses cell address A1
or lower case does not matter).
- To access the value in cell address A1 you can write
Range("A1") or Range("A1").Value. The latter is preciser.
- To tell VBA that you are writing a formula in cell
C1 you write the code Range("C1").Formula. Did you notice how the VBA
editor offers a menu once you write 'Range("C1).'. This happens only if
the syntax or grammar for accessing the cell address is correct.
- Finally define the formula to calculate the total of
data entered as shown. The formula for adding values is wrtten as
"=sum(a1:b1)" in quotes and denotes that values from cell address a1
values in cell address b1 have to be added. If you had data in cells
b1, c1, d1, e1 and wanted to apply the formula in f1 you would write
the formula "=sum(a1:e1)".