VBA Coding
Declarations
Dim (name) As (type)
Type is either integer, Boolean, double, range
Option Explicit command
o Identifies Errors instead of giving blank values
Examples
o Dim book As String
o
book = "bible"
Range("A1").Value = book
Dim continue As Boolean
continue = True
If continue = True Then MsgBox "Boolean variables are cool"//Displays
msgbox
Dim x As Integer
x = 6
Range("A1").Value = x
Range
Range Range(A#:B#).value
.value gives the value of each cell between A# and B#
Examples:
o Range("A1:A4").Value = 5
o Range("A1:A2,B3:C4").Value = 10
o Dim example As Range
Set example = Range("A1:C4")
example.Value = 8
Dim example As Range
Set example = Range("A1:C4")
o
o
example.Rows(3).Select// selects row 3 in matrix between A1 to C4
Range("A1").ClearContents // Clears the cell(s)
Dim example As Range
Set example = Range("A1:C4")
MsgBox example.Count// Gives a message box with # of cells
Dim example As Range
Set example = Range("A1:C4")
example.Select// selects the range of cells
Range(Cells(1, 1), Cells(4, 1)).Value = 5// Uses the cell functions to
declare the range
Cells Cells(>>row #<<,>>column #<<).value
Commands individual cells rather than ranges
Loops
For Loops
Declare iterating variable