AutomateExcel VBA Cheatsheet
AutomateExcel VBA Cheatsheet
Range(“A:A”).Copy
Insert
Range(“E:E”).Insert
AutoMacro:
VBA Add-in with Hundreds of Ready-To-Use Code Examples, Learn More
Code Generators, and much more! automateexcel.com/vba/cheatsheets
SETTINGS ARRAYS DICTIONARIES
Description VBA Code Description VBA Code Description VBA Code
Application.ScreenUpdating = False Dim arr(1 To 3) As Variant Required Tools > References > Microsoft Scripting
Screen Updating
Application.ScreenUpdating = True arr(1) = “one” Reference Runtime
Create
arr(2) = “two”
Application.DisplayAlerts = False arr(3) = “three” Dim dict As New Scripting.Dictionary
Display Alerts
Application.DisplayAlerts = True Create dict.Add “”
Dim arr(1 To 3) As Variant dict.Add “”
Application.EnableEvents = False Dim cell As Range, i As Integer
Events
Application.EnableEvents = True i = LBound(arr) Dim dict As New Scripting.Dictionary
Create From Dim cell As Range
For Each cell In Range(“A1:A3”)
Application.EnableCancelKey = Excel Dim key As Integer
i=i+1 Create From
Enable Cancel xlDisabled For Each cell In Range(“A1:A10”)
arr(i) = cell.value Excel
Key Application.EnableCancelKey = key = key + 1
Next cell
xlInterrupt dict.Add key, cell.value
Dim i as Long Next cell
Text Compare –
Option Compare Text Fori = LBound(arr) To UBound(arr)
Ignore Case Read All Items Add Item dict.Add “Key”, “Value”
MsgBox arr(i)
Require Variable Next i
Option Explicit Change Value dict(“Key”) = “Value”
Declaration
Erase Erase arr
Get Value MsgBox dict(“Key”)
Automatic Calcu- Application.Calculation = xlManual
Dim sName As String
lations Application.Calculation = xlAutomatic Array to String If dict.Exists(“Key”) Then
sName = Join(arr, “:”)
Check For Value MsgBox “Exists”
Application.ErrorCheckingOptions. End If
Increase Size ReDim Preserve arr(0 To 100)
Background Error BackgroundChecking = False
Checking Application.ErrorCheckingOptions. Set Value arr(1) = 22 Remove Item dict.Remove (“Key”)
BackgroundChecking = True
Remove All Items dict.RemoveAll
Display Formula Application.DisplayFormulaBar = False
Bar Application.DisplayFormulaBar = True Dim key As Variant
Application.UserName = “AutomateExcel.
UserName
com”
Application.Caption = “AutomateExcel
App Caption
Model”
Zoom ActiveWindow.Zoom = 80
AutoMacro:
VBA Add-in with Hundreds of Ready-To-Use Code Examples, Learn More
Code Generators, and much more! automateexcel.com/vba/cheatsheets