You are on page 1of 2

5 steps for creating a macro Declare variables

1. Know what you want Dim Procedure variable


2. Know how to do it without a macro Static Procedure variable that retains value
3. Record or write a macro
4. Test the macro and clean up the code Private Module variable
5. Share with others Public Globally used variable

How to record a macro Declare procedures


1. Choose Developer | Record Macro Private Function can only be called by other
Function procedures in the same module
2. Enter a macro name. No space allowed. Public Function can be called by the user and
3. Optional: Specify a keyboard shortcut, macro Function any procedure
location, and/or description. Private Sub procedure can only be called by
4. Click OK. Sub other procedures in the same module
5. Perform the actions
6. Choose Developer | Stop Recording. Public Sub Sub procedure / macro can be called by
the user or Excel and any procedure

VBA terms Decision Structures


If Condition1 Then
Object ............. Noun Statement ...... Sentence statement(s)
Property .......... Adjective Procedure ...... Paragraph ElseIf Condition2 Then
Method ........... Verb Module ........... Chapter statement(s)
Argument........ Adverb Project ............ Book Else
statement(s)
VBA code colors End If

Black ............... Regular code Select Case Variable


Case expression1
Blue ................. Keywords
statement(s)
Green .............. Comments
Case expression2
Red ................. Errors
statement(s)
Case else
Variable data types statement(s)
End Select
bln Boolean TRUE (1) or FALSE (0)
byt Byte 0 and 255 Loop Structures
int Integer -32,768 and 32,767
For counter = Start to Stop Step Increment
lng Long -2,147,483,648 and 2,147,483,647 Statement(s)
sng Single Up to 7 decimal places Next counter
dbl Double Up to 15 decimal places For Each object variable in collection
Statement(s)
cur Currency Money – up to 4 decimal places. Next
dtm Date / 1/1/0100 to 12/31/9999 Do While | Until condition
Time 00:00:00 and 23:59:59 Statement(s)
str String Text up to 2 billion characters. Loop
wkb Workbook A workbook Do
Statement(s)
wks Worksheet A worksheet Loop While | Until condition
rng Range One or more cells

Excel VBA Quick Reference Page 1


TechMentors Computer Training & Consulting Services www.TheTechMentors.com 408.375.6190
© Copyright 2011 All rights reserved
Workbook Worksheet Range
ActiveChart AutoFilter AddIndent Height PivotItem
ActiveSheet Cells Address Hidden PivotTable
AutoUpdateFrequency CircularReference AllowEdit Horizontal Precedents
Charts Columns Borders Alignment PrefixCharacter
FileFormat Comments Cells Hyperlinks Range
FullName Count Characters IndentLevel Resize
HasPassword DisplayPageBreaks Column Interior Row
HasVBAProject EnableAutoFilter Columns Item RowHeight
Properties

Name Hyperlinks ColumnWidth Locked Rows


Names Name Comment MergeArea Text
Path Names Count MergeCells UseStandardHeight
ReadOnly PageSetup CurrentRegion Name UseStandardWidth
Saved Parent Dependents NumberFormat Validation
Sheets Range End Offset Value
Worksheets Rows EntireColumn Orientation VerticalAlignment
Shapes EntireRow OutlineLevel Width
Sort Font PageBreak Worksheet
StandardHeight Formula Parent WrapText
StandardWidth FormulaR1C1 PivotCell
Visible HasFormula PivotField
Activate Activate Activate CreateNames PrintOut
AddToFavorites Add AdvancedFilter Cut PrintPreview
ApplyTheme Calculate AddComment DataSeries RemoveDuplicates
BreakLink Copy ApplyNames Delete RemoveSubtotal
Close Delete AutoFill FillDown Replace
OpenLinks Move AutoFilter FillLeft Select
PrintOut Paste AutoFit FillRight Sort
Methods

PrintPreview PasteSpecial BorderAround FillUp Subtotal


Protect PivotTableWizard Calculate Find TextToColumns
Save PrintOut CheckSpelling FindNext UnMerge
SaveAs PrintPreview Clear FindPrevious
Unprotect Protect ClearComments Insert
ResetAllPageBreaks ClearContents InsertIndent
SaveAs ClearFormats Justify
Select ClearHyperlinks Merge
Unprotect Copy PasteSpecial
Activate Activate
AfterSave BeforeDoubleClick
BeforeClose BeforeRightClick
BeforePrint Calculate
BeforeSave Change
NewChart PivotTableUpdate
Events

NewSheet The range object has no events.


Open
SheetCalculate
SheetChange
WindowActivate
WindowDeactivate
WindowResize

Excel VBA Quick Reference Page 2


TechMentors Computer Training & Consulting Services www.TheTechMentors.com 408.375.6190
© Copyright 2011 All rights reserved

You might also like