"AutoMacro is the best purchase I have made in a long time. This has helped me streamline work processes, making much of what I do much more efficient..."
Download our free Excel VBA Cheat Sheet PDF for quick reference!
VBA Cheat Sheets
Reference this page for lists of all common VBA Commands & Syntax. You will find many basic commands (ex. insert a sheet) and some advanced syntax (ex. working with arrays).
Tips:
Use CTRL + F to search this page.
Bookmark this page (CTRL + D on Chrome)!
Sheets
Description
VBA Code
Activate by Tab Name
Sheets(“Input”).Activate
Activate by VBA Code Name
Sheet1.Activate
Activate by Index Position
Sheets(1).Activate
Next Sheet
ActiveSheet.Next.Activate
Get ActiveSheet
MsgBox ActiveSheet.Name
Select Sheet
Sheets(“Input”).Select
Set to Variable
Dim ws as Worksheet Set ws = ActiveSheet
Name / Rename
ActiveSheet.Name = “NewName”
Add Sheet
Sheets.Add
Add Sheet and Name
Sheets.Add.Name = “NewSheet”
Add Sheet to Variable
Dim ws As Worksheet Set ws = Sheets.Add
Copy Sheet
Sheets(“Sheet1”).Copy Before:=Sheets(“Sheet2”)
Hide Sheet
Sheets(“Sheet1”).visible = False
or
Sheets(“Sheet1”).visible = xlSheetHidden
Unhide Sheet
Sheets(“Sheet1”).Visible = True
or
Sheets(“Sheet1”).Visible = xlSheetVisible
Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!
With ActiveWindow
.DisplayHorizontalScrollBar = False
.DisplayVerticalScrollBar = False End WithWith ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True End With
Dim dict As New Scripting.Dictionary
dict.Add “”
dict.Add “”
Create From Excel
Dim dict As New Scripting.Dictionary Dim cell As Range Dim key As Integer
For Each cell In Range(“A1:A10”)
key = key + 1
dict.Add key, cell.value Next cell
Add Item
dict.Add “Key”, “Value”
Change Value
dict(“Key”) = “Value”
Get Value
MsgBox dict(“Key”)
Check For Value
If dict.Exists(“Key”) Then
MsgBox “Exists” End If
Remove Item
dict.Remove (“Key”)
Remove All Items
dict.RemoveAll
Loop Through Items
Dim key As Variant For Each key In dict.Keys
MsgBox key, dict(key) Next key
AutoMacro is an add-in for VBA that installs directly into the Visual Basic Editor. It comes loaded with code generators, an extensive code library, the ability to create your own code library, and many other time-saving tools and utilities that add much needed functionality to the outdated VBA Editor.