VBA Code Examples for Excel

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about Easy VBA. A VBA add-in to quickly insert any of the sample code found on our site directly into the Visual Basic Editor, save your own frequently used code, and more!

alt text

Stop searching for VBA code online. Try the Code VBA Add-in…

Learn More!

Use this searchable list to find the VBA code that you are looking for.

VBA Code Samples
Sort Sheets Alphabetically with VBA
Delete Rows that Meet Certain Criteria in VBA
VBA Save File - 20 Easy Examples
VBA: Extract Number From String
VBA Routine to return Column Letter of Cell
VBA Function to Show Cell Formula
Convert Matrix to Vector
Find the nth Word in a String
Converting a Single Row Vector into a Matrix
How to Create a Bar Chart using VBA
Finding the Maximum Value in Each Column in a Range
VBA Routine to Add and Name Worksheets
VBA: Highlight Duplicates in a Range
VBA: Calculate Acronyms from Strings
Sum by Color
VBA: UDF to perform a 3-parameter Vlookup
VBA and Vlookup: Find occurence of string
VBA: Excel's Colour Scheme
VBA Function: Populating a Range
VBA: List of all files contained within a Directory
VBA Function To Calculate Number of Words in a String
VBA Function to Compare Dates
VBA: Subroutine to Reverse a String
WorkBook Events – Don’t save with Freeze Panes
VBA: Selecting Every 5th Row
Export Range to Delimited Text File
Get Current Weather in Excel
VBA: Array Examples
VBA: Remove Characters from Left or Right Side of Variable Length String
Image Control Problem - Can't LoadPicture() from URL
VBA: WinHttpRequest with Login and Password - Misc Bloglines
VBA: Language References
VBA: Yes or No Message Box
VBA: Delete All Named Ranges
VBA: Zoom - Fit Selection
VBA: Loop Through a String
VBA: Delete Hyperlinks
Hide WorkSheet Tabs
VBA: ActiveWindow.WindowState
VBA: Transparent Forms
VBA: Unhide All Worksheets
Excel VBA: Named Ranges and Programming
VBA: Remove Blank Rows
VBA: Test if Selection is Range
VBA: Size an Object to a Range Size
VBA: Delete All Autoshapes
VBA: Speak to Me
VBA: Code Indenter
VBA: Consume Soap Web Services
VBA: Determine a Variable's Underlying Type
VBA: Force a Workbook to Save
VBA: Zoom...Zoom
VBA: Turn Off - Turn On Calculation
VBA: Page Break Preview
VBA: Hide a Macro
VBA: Exit Without Saving
VBA: Row Height - Column Width
VBA: Add Spaces to a String - Space()
VBA: Turn On Formula Bar - Turn Off Formula Bar
VBA: Check Spelling
VBA: Display Fullscreen
VBA: Join Multiple Ranges
VBA: Benchmarking Code
VBA: Change a Cells Background Color
VBA: Run a Macro When a Cell Changes
VBA: Select All Cells
VBA: Format Painter
VBA: Macro to List all Sheets in a Workbook
VBA: Programmatically Draw Boxes with Code
VBA: Macro to Create a Hyperlink Menu of Worksheets
VBA: Scroll Vertically and Scroll Horizontally
VBA: Use Worksheet Functions in a Macro
Delete files from the hard drive
Hide Excel (The Entire Application)
VBA: Cut, Copy, Paste from a Macro
Launch Internet Explorer from VBA
Search Google from a cell
VBA: Determine Start and End Column of a Merged Cell
Modify the titlebar
Modify the right-click menu to call a macro
VBA: How To Activate a Sheet
VBA: Prevent warning messages from a macro
VBA: Get the active cell's Column
VBA: Autofit Columns
VBA: Run a macro when Excel starts
VBA: Find Text in a String (instr)
VBA: Input from a User in a Macro (InputBox)
VBA: Loop Through a Range
VBA: Code or Program a Data Validation List
VBA: Run a Macro from a Macro
VBA: Convert Excel to CSV (Comma Delimited Text File)
VBA: Turn off Screen Updating
VBA: Remove Formatting For Each Cell In Range
VBA: Line Break or Line Feed in a Message Box
VBA: Force Proper, Upper, or Lower case automatically
VBA: Macro to Autofill
VBA: Count the sheets in a Workbook
VBA: Run a Macro Line by Line
VBA: Macro to Update all Worksheets in Workbook
VBA: Count the rows in a Selection
VBA: Status Bar Updating
VBA: Use a Variable in Multiple Modules or Subs
VBA: Turn Off Autofilter From Code
VBA: Run a macro when Excel closes
VBA: Add or Remove Cell Comments from a Macro
VBA: Hide a worksheet
VBA: Show or load a form when Excel starts
VBA: Select Non Contiguous Columns
VBA: Set the Default Sheet When a WorkBook Opens
Change User Name with VBA
Start a Screen Saver with VBA
VBA - Wait, Delay, Create a Timer While Running Code
Environ Function - Excel VBA
VBA - Programming the VBE (Visual Basic Editor)
VBA Best Practices
VBA Turn Scroll Bars On or Off
VBA - Test if Workbook is Open by Workbook Name
VBA: Count the Number of Used Rows