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    
Basics
Cut, Copy, Paste from a Macro
Save File - 20 Easy Examples
Ranges and Cells
Select Range
Offset Range or Cell
Select All Cells
Get the active cell's Column
Test if Selection is Range
Merge Cells
Bold Text in a Cell
Wrap Text
Finding the Maximum Value in Each Column in a Range
VBA Function: Populating 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 & Columns
Delete Rows that Meet Certain Criteria in VBA
Converting a Single Row Vector into a Matrix
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
Sheets
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
Sort Sheets Alphabetically with VBA
Macro to List all Sheets in a Workbook
Count the sheets in a Workbook
Hide WorkSheet Tabs
Unhide All Worksheets
Macro to Create a Hyperlink Menu of Worksheets
Use Worksheet Functions in a Macro
Macro to Update all Worksheets in Workbook
Set the Default Sheet When a WorkBook Opens
Workbooks
Open / Close Workbook
Merge Workbooks
Files
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 Strings
Text Strings and Substrings Functions
Extract Number From String
Find the nth Word in a String
Concatenate Text(&)
New Line / Carriage Return
Calculate Acronyms from Strings
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)
VBA Coding Concepts
Guide to Debug.Print & Immediate Window
Code Indenter
VBA Best Practices
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
Hide a Macro
Commenting
On Error Exit Sub
Option Explicit
DoEvents
Exit Sub Or Function
End All Code Execution
Events
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
Loops
Exit Loop
Exit For
Settings
Turn off Screen Updating
Turn Off - Turn On Calculation
Status Bar Updating
VBA Turn Scroll Bars On or Off
Change User Name with VBA
Turn On Formula Bar - Turn Off Formula Bar
Prevent warning messages from a macro
Modify the titlebar
In Depth Tutorials (Updating Soon)
Array Examples
Loop Through a Range
Formatting
Format Painter
Excel's Colour Scheme
Shapes, Charts, and Objects
Guide to Charts and Graphs
Guide to Pivot Tables
Guide to Objects
Programmatically Draw Boxes with Code
Delete All Autoshapes
How to Create a Bar Chart using VBA
Tables and ListObjects
AutoFilters
UserForms & Controls
Open / Close UserForm
ListBox
ComboBox
CheckBox
Spin Button
Option Button
Misc.
Hyperlinks
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
Speak to Me
Start a Screen Saver with VBA
Get Current Weather in Excel
User Interaction
Yes or No Message Box
Transparent Forms
Input from a User in a Macro (InputBox)
Line Break or Line Feed in a Message Box
View
Zoom - Fit Selection
Zoom...Zoom
WorkBook Events – Don’t save with Freeze Panes
Scroll Vertically and Scroll Horizontally
Page Break Preview
Display Fullscreen
Hide Excel (The Entire Application)
ActiveWindow.WindowState
Variables
Data Types - Variables and Constants
Range Variables
Global Variables
Public Variables - Use in Multiple Modules or Subs
Array Variables
Static Variables
Date Variable
Declare Variables - Dim
Constant Expression Required
Determine a Variable's Underlying Type
Internet
WinHttpRequest with Login and Password - Misc Bloglines
Consume Soap Web Services
Launch Internet Explorer from VBA
Image Control Problem - Can't LoadPicture() from URL
Search Google from a cell
Advanced Programming
Convert Matrix to Vector
VBA - Programming the VBE (Visual Basic Editor)
Timer Function
SendKeys
Guide to RegEx
Functions
Date Functions
Check if Sheet and/or Range Exists
UDF to perform a 3-parameter Vlookup
Environ Function - Excel VBA
Compare Dates
Show Cell Formula
Isnumber / Isnumeric
IsEmpty / IsBlank
Round, RoundUp, RoundDown
Macro Basics
Record a Macro
Editing Macros
Run a Macro
Add a button and Assign a Macro
Macros Disabled? How to Enable Macros

Ads