Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.13 KB

vba_all.md

File metadata and controls

44 lines (33 loc) · 1.13 KB

VBA for Excel

Tools

  • MS Excel (recommended 2016)
  • Sublime Text 3 (with VBScript package installed)

Coding guidelines

  • 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.

Websites