VBA

Preamble

Option Explicit

'Comment

Public Function myFunc(x as Double, y as Integer, myRange as Range) As Double
    disp(myRange.Cells(1,2))
    myFunc = x*y * (myRange.Rows.Count * myRange.Columns.Count)
End Function

Data types

The types are:

Dim mystring as String

Dim myFixedArray(1 to 5, 1 to 15) as Double

Dim myVariableArray() As Double
Redim myVariableArray(1 to 4, 1 to 2)
myVariableArray(3,1)

Statements

New line separated usually. Can use colon to separate statements in a single line Var1 = 10: Var2 = 20

Conditional Execution

If test = 0 Then
    statements
ElseIf test = 1 Or test = 2 And test > 1 Then
    statements
Else
    statements
End If          
Select Case index
    Case 1,2
        statements
    Case Is < 0
        statements
    Case 10 To 20
        statements
    Case Else
        statements
End Select

Loops

Dim index as Integer

For index = j To k [step m]
    statements
Next index

Do While condition
    statements
Loop

Date Functions

Date Day(x) Weekday(x) Month(x) Year(x)

User Functions

Can’t have . in the name.

No return statement. Set variable to func name. Then call Exit Function.

Function test(ByVal return1 As Boolean) As Integer
    If return1 Then
        test = 1
        Exit Function
    End If
    'more code...
    test = 2
End Function