You are on page 1of 2

Creating our own Function: Open VBA Editor: -Click Insert/Module -Type in Function - Return to editor and test

- Functions will be saved with the worksheet and won't be available to other worksheets. It is possible to make it always available, by saving macros in Calling the Functions Once the function is defined, we can call it as if it was already built into Excel (eg..) Cell B4 = tend(B1,02) Developer > Visual Basic Function tend(v,theta) g=9.31 tend=2*v*Sin(theta)/g End Function The above function can be used in Excel worksheet. ================================= VBA Window Alt+F11 View Macros Alt+F8 /*****A Simple Macro****/ Open a Worksheet > Alt+F11 > It will open a VBA Editor Insert > Userform --> Type the simple code > then press Alt+F11

Sub Message_Box() MsgBox "This is my first Macro!" End Sub It will return back to Excel sheet Then press Alt+F8 > It will ask for the Macro to run. Select the above macro and press Run MsgBox will appear. ================================= Sub Avg_Calc()

'Range ("D4").Formula = "=Average(B4.C4)" For single cell Range("D4:D7").Formula = "=Average(B4.C4)" End Sub 'For Range of cells

You might also like