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 are professionally developed and ready-to-use.

VBA Code Examples
Basics
Cut, Copy, Paste from a Macro
Save File - 20 Easy Examples
Ranges and Cells
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
Test if Selection is Range
Change a Cells Background Color
Select All Cells
Get the active cell's Column
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
Sort Sheets Alphabetically with VBA
Macro to List all Sheets in a Workbook
Count the sheets in a Workbook
VBA Routine to Add and Name Worksheets
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
Hide a worksheet
How To Activate a Sheet
Set the Default Sheet When a WorkBook Opens
Files
List of all files contained within a Directory
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
File Exists
Copy File
Delete File
Rename File
Open File Dialog
Text and Strings
Extract Number From String
Find the nth Word in a String
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
VBA Coding Concepts
VBA Code Library
Code Indenter
VBA - Programming the VBE (Visual Basic Editor)
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
Events
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
Programmatically Draw Boxes with Code
Delete All Autoshapes
How to Create a Bar Chart using VBA
Add or Remove Cell Comments from a Macro
Delete Hyperlinks
ListBox
ComboBox
CheckBox
Misc.
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
Use a Variable in Multiple Modules or Subs
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
Functions
UDF to perform a 3-parameter Vlookup
Environ Function - Excel VBA
Compare Dates
Show Cell Formula
Isnumber / Isnumeric