VBA & Office Scripts examples
Copy-ready VBA macros, Office Scripts snippets and spreadsheet automation workflows for reports, files, PDFs, Outlook email, ranges, loops, events and recurring Excel tasks.
Browse automation examples
Filter by VBA basics, ranges, cleaning, workbooks, reports, email, events, advanced VBA and Office Scripts.
VBA For Each Loop Examples
Loop through cells, worksheets, workbooks, files, and table rows with For Each in Excel VBA.
VBA BasicsVBA For Next Loop Examples
Repeat tasks a fixed number of times, loop through row numbers, and build simple counters in VBA.
VBA BasicsVBA Do While Loop Examples
Run VBA code while a condition is true, such as reading rows until a blank cell appears.
VBA BasicsVBA IF THEN Examples
Use IF, ELSEIF, and ELSE in VBA to make decisions in spreadsheets and reports.
VBA BasicsVBA Select Case Examples
Replace long IF statements with clearer Select Case logic in Excel macros.
Ranges & RowsVBA Last Row Examples
Find the last used row in a sheet, table, or specific column before copying or reporting data.
Ranges & RowsVBA Last Column Examples
Find the last used column in a worksheet, header row, or report table.
Ranges & RowsVBA Copy Paste Range Examples
Copy values, formulas, formats, and ranges between sheets with VBA.
Ranges & RowsVBA Copy Rows to Another Sheet Examples
Move or copy matching rows into another worksheet for summaries and reports.
Ranges & RowsVBA Clear Contents Examples
Clear values, formulas, comments, formats, or old report areas safely.
Ranges & RowsVBA Delete Blank Rows Examples
Remove empty rows from imported files, reports, and data entry sheets.
Ranges & RowsVBA Insert Rows Examples
Insert single or multiple rows in the right place without breaking formulas.
Data CleaningVBA Filter Rows Examples
Filter rows by status, date, region, or amount using Excel VBA.
Data CleaningVBA Sort Data Examples
Sort data by one or more columns before exporting or building reports.
Data CleaningVBA Find Value Examples
Find IDs, names, dates, and missing records in worksheets using VBA.
Data CleaningVBA Replace Text Examples
Replace text, codes, spaces, and unwanted characters in Excel data.
FormattingVBA Format Cells Examples
Apply number formats, font styles, borders, colors, and alignment with VBA.
FormattingVBA Conditional Formatting Examples
Add conditional formatting rules for overdue dates, high values, and duplicates.
Sheets & WorkbooksVBA Create Worksheet Examples
Create new worksheets for reports, months, departments, and exports.
Sheets & WorkbooksVBA Rename Worksheet Examples
Rename worksheets safely using dates, names, and cleaned values.
Sheets & WorkbooksVBA Loop Through Worksheets Examples
Loop through every sheet in a workbook for formatting, clearing, and reporting tasks.
Sheets & WorkbooksVBA Protect Sheet Examples
Protect worksheets, allow user edits, and avoid accidental formula changes.
Sheets & WorkbooksVBA Unprotect Sheet Examples
Unprotect sheets safely before running a controlled macro task.
Files & PDFsVBA Open Workbook Examples
Open source workbooks, templates, and report files with Excel VBA.
Files & PDFsVBA Save Workbook Examples
Save workbooks, backups, report copies, and timestamped files.
Files & PDFsVBA Save As PDF Examples
Save sheets, reports, and selected ranges as PDF files with VBA.
Files & PDFsVBA Export Sheet to PDF Examples
Export a single worksheet or report tab as a PDF for sharing.
Files & PDFsVBA Import CSV Examples
Import CSV files into Excel and prepare them for cleaning or reporting.
Files & PDFsVBA Combine Workbooks Examples
Combine multiple Excel files into one summary workbook or master sheet.
Reports & PivotsVBA Refresh PivotTables Examples
Refresh all PivotTables before sending or exporting a report.
Reports & PivotsVBA Refresh Power Query Examples
Refresh workbook queries and connections with VBA before publishing reports.
Reports & PivotsVBA Create PivotTable Examples
Create a basic PivotTable from a source range or table with VBA.
Email & PDFVBA Send Email with Outlook Examples
Create Outlook emails from Excel with subject, body, recipients, and attachments.
Email & PDFVBA Email Workbook as Attachment Examples
Attach the active workbook, a saved copy, or a PDF report to an Outlook email.
Events & ButtonsVBA Run Macro on Open Examples
Run startup actions when a workbook opens, such as refreshing data or showing instructions.
Events & ButtonsVBA Worksheet Change Event Examples
Trigger code when users edit cells, change statuses, or enter new data.
Events & ButtonsVBA Button Click Macro Examples
Connect buttons to macros for refresh, export, clear, and report actions.
VBA BasicsVBA InputBox Examples
Ask users for values such as dates, names, months, and folder paths.
VBA BasicsVBA MessageBox Examples
Show confirmations, warnings, and simple macro messages with MsgBox.
VBA BasicsVBA Error Handling Examples
Use On Error safely to handle missing files, bad inputs, and protected sheets.
Advanced VBAVBA Array Examples
Use arrays to process data faster than looping directly through worksheet cells.
Advanced VBAVBA Dictionary Examples
Use dictionaries for unique lists, counts, lookups, and fast matching.
Advanced VBAVBA Table ListObject Examples
Work with Excel Tables, rows, columns, filters, and totals using ListObjects.
Data CleaningVBA Split Text to Columns Examples
Split names, codes, CSV-style values, and imported text fields with VBA.
Data CleaningVBA Remove Duplicates Examples
Remove duplicate rows or values in a controlled data-cleaning workflow.
Reports & PivotsVBA Create Report Examples
Build repeatable report sheets from raw data with formatting and summary steps.
Reports & PivotsVBA Dashboard Refresh Examples
Refresh queries, PivotTables, charts, and timestamps for dashboard workbooks.
Office ScriptsOffice Scripts Format Table Examples
Format Excel tables in the web version of Excel using Office Scripts.
Office ScriptsOffice Scripts Clear Filters Examples
Clear table and worksheet filters before refreshing or exporting data.
Office ScriptsOffice Scripts Create Worksheet Examples
Create, name, and prepare worksheets in Office Scripts.
Office ScriptsOffice Scripts Update Range Examples
Write values, formulas, and report labels into ranges with Office Scripts.
Office ScriptsOffice Scripts Read Table Examples
Read Excel table rows and columns in Office Scripts workflows.
Office ScriptsOffice Scripts Add Formulas Examples
Add formulas to tables, ranges, and calculated columns with Office Scripts.
Office ScriptsOffice Scripts Refresh Workbook Examples
Refresh workbook connections and prepare online Excel reports.
Office ScriptsOffice Scripts Loop Through Rows Examples
Loop through rows in a table to update statuses, flags, and calculated fields.
Office ScriptsOffice Scripts Find and Replace Examples
Find and replace values across ranges, sheets, and tables in Office Scripts.
Office ScriptsOffice Scripts Copy Data Between Sheets Examples
Copy data from one worksheet to another in Excel on the web.
Office ScriptsOffice Scripts Delete Blank Rows Examples
Remove blank rows from a worksheet or table with Office Scripts.
Office ScriptsOffice Scripts Monthly Report Automation Examples
Automate recurring monthly report steps with Office Scripts.
No matching examples found. Try another search or filter.
Here are some ideas for you
Optional resources that may help if you are learning Excel automation, building reports, or automating spreadsheets often.
- Excel VBA booksSee ideas
Learn macro patterns, objects, ranges and real automation examples.
- Office Scripts resourcesSee ideas
Practice automating Excel on the web with repeatable script patterns.
- Productivity keyboardsSee ideas
Helpful for writing code, formulas and documentation for long sessions.
- External monitorsSee ideas
View the workbook, VBA editor, script editor and notes side by side.
- External backup drivesSee ideas
Useful for keeping backup copies of automation workbooks and reports.
- Workflow notebooksSee ideas
Sketch macro steps, report logic and safety checks before coding.
Some links in this section may be affiliate links. Choose only what is useful for your own work.