Catalog / VBA Cheat Sheet
VBA Cheat Sheet
A concise reference for Visual Basic for Applications (VBA), covering essential syntax, functions, and techniques for automating tasks within Microsoft Office applications.
VBA Fundamentals
Data Types
Integer |
Whole numbers between -32,768 and 32,767. |
Long |
Whole numbers between -2,147,483,648 and 2,147,483,647. |
Single |
Single-precision floating-point numbers. |
Double |
Double-precision floating-point numbers. |
String |
Sequence of characters. |
Boolean |
|
Date |
Represents dates and times. |
Variant |
Can store any data type. Default if no type is specified. |
Variable Declaration
Example:
|
Variables must be declared before use. Use |
Operators
Arithmetic |
|
Comparison |
|
Logical |
|
String Concatenation |
|
Control Structures
Conditional Statements
If…Then…Else
|
Select Case
|
Looping Structures
For…Next
|
For Each…Next
|
Do While…Loop
|
Do…Loop While
|
Do Until…Loop
|
Do…Loop Until
|
Working with Objects
Object References
Excel Application |
|
Workbook |
|
Worksheet |
|
Range |
|
Object Properties & Methods
Objects have properties (attributes) and methods (actions). Syntax: |
Example:
|
Procedures and Functions
Sub Procedures
Subs do not return a value. |
Example:
|
Function Procedures
Functions return a value. |
Example:
|
Built-in Functions
MsgBox |
Displays a message box. |
InputBox |
Displays an input box. |
Len |
Returns the length of a string. |
Left, Right, Mid |
Extracts a substring. |
UCase, LCase |
Converts string to upper/lower case. |
Date, Time |
Returns the current date/time. |