- MS Excel (recommended 2016)
- Sublime Text 3 (with VBScript package installed)
- Function: A module defined for being called into any sheet in an excel workbook.
- Open VB editor.
- Insert >> Module
- Code sample:
Function Area(x As Double, y As Double) As Double
Area = x * y
End Function
NOTE: you will also find that user-defined function within a cell after typing "=".
- Sub procedure: defined for a sheet in an excel workbook.
- View project structure on the left panel of the editor.
- select any sheet - "Sheet1".
- insert this code below:
Private Sub CommandButton1_Click()
' find the area using a Area module
Dim z as Double
z = Area(2, 5) + 5
MsgBox(z)
End Sub
NOTE: Sub vs Function -
Sub doesn't return anything. But, Function returns as Integer, Double, String, Long, etc.