VBA + Excel

VBA Code Examples

AutoMacro: VBA Add-in with 200+ Ready-To-Use VBA Code Examples & much more!

Search the list below for free Excel VBA code examples complete with explanations.
Some include downloadable files as well. These Excel VBA Macros & Scripts are professionally developed and ready-to-use.

We hope you find this list useful!

VBA Code Examples 
Guide to Loops - Fors, Dos and More
If, If-Else, And, Or
Select Case
Cut, Copy, Paste from a Macro
Save File - 20 Easy Examples
Ranges and Cellsyes
Get / Set Cell Values
Select Range
Offset Range or Cell
Select All Cells
Get the active cell's Column
Change Cell Font Properties
Clear Cells
Test if Selection is Range
Merge Cells
Bold Text in a Cell
Wrap Text
Range Address
Finding the Maximum Value in Each Column in a Range
Delete All Named Ranges
Highlight Duplicates in a Range
Join Multiple Ranges
Remove Formatting For Each Cell In Range
Size an Object to a Range Size
Change a Cells Background Color
Return Column Letter of Cell
Determine Start and End Column of a Merged Cell
Macro to Autofill
Sum by Color
Rows & Columnsyes
Delete Rows that Meet Certain Criteria in VBA
Selecting Every 5th Row
Remove Blank Rows
Row Height - Column Width
Count the rows in a Selection
Count the Number of Used Rows
Autofit Columns
Select Non Contiguous Columns
Ultimate Guide to Worksheets
Activate, Select Sheet and Working with ActiveSheet
Add / Insert Worksheet
Copy Worksheet
Hide / Unhide Worksheets
Delete or Clear Worksheet
Get Sheet Name / Rename Sheet
Unprotect / Protect Worksheets
Macro to List all Sheets in a Workbook
Count the sheets in a Workbook
Hide WorkSheet Tabs
Unhide All Worksheets
Clear Entire Sheet
Macro to Create a Hyperlink Menu of Worksheets
Macro to Update all Worksheets in Workbook
Set the Default Sheet When a WorkBook Opens
Create New Workbook
Open / Close Workbook
Merge Workbooks
List of all files contained within a Directory
List Files in Folder
Export Range to Delimited Text File
Delete files from the hard drive
Convert Excel to CSV (Comma Delimited Text File)
VBA - Test if Workbook is Open by Workbook Name
Validate Filenames
File Exists
Copy File
Delete File
Rename File
Open File Dialog
Text and Stringsyes
Text Strings and Substrings Functions
Extract Number From String
Find the nth Word in a String
Concatenate Text(&)
New Line / Carriage Return
VBA and Vlookup: Find occurence of string
VBA Function To Calculate Number of Words in a String
Subroutine to Reverse a String
Remove Characters from Left or Right Side of Variable Length String
Loop Through a String
Add Spaces to a String - Space()
Find Text in a String (instr)
Force Proper, Upper, or Lower case automatically
Char / Chr Function
Upper, Lower, and Proper Case - Case Functions
Prevent VBA Case Sensitive
Like Operator
Logical Operators
Comparison Operators - Not Equal To and More
Compare Strings (StrComp)
Convert Text to Number
Convert Number to Text
VBA Coding Conceptsyes
Guide to Debug.Print & Immediate Window
Code Formatter Add-in
Online VBA Code Indenter
GoTo Line Label
Run a Macro Line by Line
Excel Named Ranges and Programming
Run a Macro from a Macro
Language References
Modify the right-click menu to call a macro
Benchmarking Code
VBA - Wait, Delay, Create a Timer While Running Code
On Error Exit Sub
Option Explicit
Exit Sub Or Function
End All Code Execution
Run Macro on Excel Open
Show or load a form when Excel starts
Run a macro when Excel closes
Run a Macro When a Cell Changes
Force a Workbook to Save
Exit Without Saving
For Each Loop Examples
Exit Loop
Exit For
Turn off Screen Updating
Turn Off - Turn On Calculation
Calculate Now
Status Bar Updating
VBA Turn Scroll Bars On or Off
Turn On Formula Bar - Turn Off Formula Bar
Prevent warning messages from a macro
In Depth Tutorials (Updating Soon)yes
Array Examples
Loop Through a Range
Format Painter
Excel's Colour Scheme
Shapes, Charts, and Objectsyes
Guide to Charts and Graphs
Guide to Pivot Tables
Guide to Objects
Delete All Autoshapes
How to Create a Bar Chart using VBA
Tables and ListObjects
UserForms & Controlsyes
Open / Close UserForm
Spin Button
Option Button
Delete Hyperlinks
Add or Remove Cell Comments from a Macro
Random Numbers
Check Spelling
Turn Off Autofilter From Code
Code or Program a Data Validation List
User Interactionyes
Yes or No Message Box
Input from a User in a Macro (InputBox)
Line Break or Line Feed in a Message Box
Zoom - Fit Selection
WorkBook Events – Don’t save with Freeze Panes
Scroll Vertically and Scroll Horizontally
Page Break Preview
Display Fullscreen
Hide Excel (The Entire Application)
Data Types - Variables and Constants
Range Variables
Global Variables
Public Variables - Use in Multiple Modules or Subs
Array Variables
Date Variable
Declare Variables - Dim
Constant Expression Required
Launch Internet Explorer from VBA
Advanced Programmingyes
Advanced VBA Examples
Timer Function
Guide to RegEx
Date Functions
Check if Sheet and/or Range Exists
UDF to perform a 3-parameter Vlookup
Compare Dates
Isnumber / Isnumeric
IsEmpty / IsBlank
Round, RoundUp, RoundDown
Macro Basicsyes
Record a Macro
Editing Macros
Run a Macro
Add a button and Assign a Macro
Macros Disabled? How to Enable Macros

Automate Excel
Left Menu Icon