🧩 Excel automation examples

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.

59 automation pages295 practical examplesCopy-ready code

Browse automation examples

Filter by VBA basics, ranges, cleaning, workbooks, reports, email, events, advanced VBA and Office Scripts.

VBA Basics

VBA For Each Loop Examples

Loop through cells, worksheets, workbooks, files, and table rows with For Each in Excel VBA.

VBA Basics

VBA For Next Loop Examples

Repeat tasks a fixed number of times, loop through row numbers, and build simple counters in VBA.

VBA Basics

VBA Do While Loop Examples

Run VBA code while a condition is true, such as reading rows until a blank cell appears.

VBA Basics

VBA IF THEN Examples

Use IF, ELSEIF, and ELSE in VBA to make decisions in spreadsheets and reports.

VBA Basics

VBA Select Case Examples

Replace long IF statements with clearer Select Case logic in Excel macros.

Ranges & Rows

VBA Last Row Examples

Find the last used row in a sheet, table, or specific column before copying or reporting data.

Ranges & Rows

VBA Last Column Examples

Find the last used column in a worksheet, header row, or report table.

Ranges & Rows

VBA Copy Paste Range Examples

Copy values, formulas, formats, and ranges between sheets with VBA.

Ranges & Rows

VBA Copy Rows to Another Sheet Examples

Move or copy matching rows into another worksheet for summaries and reports.

Ranges & Rows

VBA Clear Contents Examples

Clear values, formulas, comments, formats, or old report areas safely.

Ranges & Rows

VBA Delete Blank Rows Examples

Remove empty rows from imported files, reports, and data entry sheets.

Ranges & Rows

VBA Insert Rows Examples

Insert single or multiple rows in the right place without breaking formulas.

Data Cleaning

VBA Filter Rows Examples

Filter rows by status, date, region, or amount using Excel VBA.

Data Cleaning

VBA Sort Data Examples

Sort data by one or more columns before exporting or building reports.

Data Cleaning

VBA Find Value Examples

Find IDs, names, dates, and missing records in worksheets using VBA.

Data Cleaning

VBA Replace Text Examples

Replace text, codes, spaces, and unwanted characters in Excel data.

Formatting

VBA Format Cells Examples

Apply number formats, font styles, borders, colors, and alignment with VBA.

Formatting

VBA Conditional Formatting Examples

Add conditional formatting rules for overdue dates, high values, and duplicates.

Sheets & Workbooks

VBA Create Worksheet Examples

Create new worksheets for reports, months, departments, and exports.

Sheets & Workbooks

VBA Rename Worksheet Examples

Rename worksheets safely using dates, names, and cleaned values.

Sheets & Workbooks

VBA Loop Through Worksheets Examples

Loop through every sheet in a workbook for formatting, clearing, and reporting tasks.

Sheets & Workbooks

VBA Protect Sheet Examples

Protect worksheets, allow user edits, and avoid accidental formula changes.

Sheets & Workbooks

VBA Unprotect Sheet Examples

Unprotect sheets safely before running a controlled macro task.

Files & PDFs

VBA Open Workbook Examples

Open source workbooks, templates, and report files with Excel VBA.

Files & PDFs

VBA Save Workbook Examples

Save workbooks, backups, report copies, and timestamped files.

Files & PDFs

VBA Save As PDF Examples

Save sheets, reports, and selected ranges as PDF files with VBA.

Files & PDFs

VBA Export Sheet to PDF Examples

Export a single worksheet or report tab as a PDF for sharing.

Files & PDFs

VBA Import CSV Examples

Import CSV files into Excel and prepare them for cleaning or reporting.

Files & PDFs

VBA Combine Workbooks Examples

Combine multiple Excel files into one summary workbook or master sheet.

Reports & Pivots

VBA Refresh PivotTables Examples

Refresh all PivotTables before sending or exporting a report.

Reports & Pivots

VBA Refresh Power Query Examples

Refresh workbook queries and connections with VBA before publishing reports.

Reports & Pivots

VBA Create PivotTable Examples

Create a basic PivotTable from a source range or table with VBA.

Email & PDF

VBA Send Email with Outlook Examples

Create Outlook emails from Excel with subject, body, recipients, and attachments.

Email & PDF

VBA Email Workbook as Attachment Examples

Attach the active workbook, a saved copy, or a PDF report to an Outlook email.

Events & Buttons

VBA Run Macro on Open Examples

Run startup actions when a workbook opens, such as refreshing data or showing instructions.

Events & Buttons

VBA Worksheet Change Event Examples

Trigger code when users edit cells, change statuses, or enter new data.

Events & Buttons

VBA Button Click Macro Examples

Connect buttons to macros for refresh, export, clear, and report actions.

VBA Basics

VBA InputBox Examples

Ask users for values such as dates, names, months, and folder paths.

VBA Basics

VBA MessageBox Examples

Show confirmations, warnings, and simple macro messages with MsgBox.

VBA Basics

VBA Error Handling Examples

Use On Error safely to handle missing files, bad inputs, and protected sheets.

Advanced VBA

VBA Array Examples

Use arrays to process data faster than looping directly through worksheet cells.

Advanced VBA

VBA Dictionary Examples

Use dictionaries for unique lists, counts, lookups, and fast matching.

Advanced VBA

VBA Table ListObject Examples

Work with Excel Tables, rows, columns, filters, and totals using ListObjects.

Data Cleaning

VBA Split Text to Columns Examples

Split names, codes, CSV-style values, and imported text fields with VBA.

Data Cleaning

VBA Remove Duplicates Examples

Remove duplicate rows or values in a controlled data-cleaning workflow.

Reports & Pivots

VBA Create Report Examples

Build repeatable report sheets from raw data with formatting and summary steps.

Reports & Pivots

VBA Dashboard Refresh Examples

Refresh queries, PivotTables, charts, and timestamps for dashboard workbooks.

Office Scripts

Office Scripts Format Table Examples

Format Excel tables in the web version of Excel using Office Scripts.

Office Scripts

Office Scripts Clear Filters Examples

Clear table and worksheet filters before refreshing or exporting data.

Office Scripts

Office Scripts Create Worksheet Examples

Create, name, and prepare worksheets in Office Scripts.

Office Scripts

Office Scripts Update Range Examples

Write values, formulas, and report labels into ranges with Office Scripts.

Office Scripts

Office Scripts Read Table Examples

Read Excel table rows and columns in Office Scripts workflows.

Office Scripts

Office Scripts Add Formulas Examples

Add formulas to tables, ranges, and calculated columns with Office Scripts.

Office Scripts

Office Scripts Refresh Workbook Examples

Refresh workbook connections and prepare online Excel reports.

Office Scripts

Office Scripts Loop Through Rows Examples

Loop through rows in a table to update statuses, flags, and calculated fields.

Office Scripts

Office Scripts Find and Replace Examples

Find and replace values across ranges, sheets, and tables in Office Scripts.

Office Scripts

Office Scripts Copy Data Between Sheets Examples

Copy data from one worksheet to another in Excel on the web.

Office Scripts

Office Scripts Delete Blank Rows Examples

Remove blank rows from a worksheet or table with Office Scripts.

Office Scripts

Office Scripts Monthly Report Automation Examples

Automate recurring monthly report steps with Office Scripts.

💡 Useful resources

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 books

    Learn macro patterns, objects, ranges and real automation examples.

    See ideas
  • 🧩
    Office Scripts resources

    Practice automating Excel on the web with repeatable script patterns.

    See ideas
  • ⌨️
    Productivity keyboards

    Helpful for writing code, formulas and documentation for long sessions.

    See ideas
  • 🖥️
    External monitors

    View the workbook, VBA editor, script editor and notes side by side.

    See ideas
  • 💾
    External backup drives

    Useful for keeping backup copies of automation workbooks and reports.

    See ideas
  • 📒
    Workflow notebooks

    Sketch macro steps, report logic and safety checks before coding.

    See ideas

Some links in this section may be affiliate links. Choose only what is useful for your own work.