Wauvel

Excel like a finance pro.

← The library

VBA · Syntax

Sub procedures

A block of code that performs actions and returns nothing; every macro is a Sub.

Daily driverDifficulty 950 · Capable
Practice · 2 questions →

When to use it

A Sub procedure is a named block of statements that does something and returns nothing. Every macro you run from the Macros dialog or a button is a Sub.

The code

Code
Sub CleanUp()
  Range("A1").ClearContents
End Sub

Worked examples

  • A minimal macro

    Sub CleanUp() Range("A1").ClearContents End Sub A macro named CleanUp that clears A1

    Run it with F5 or Alt + F8.

  • With a parameter

    Sub Report(region As String) MsgBox "Building " & region End Sub A Sub with a parameter, called as Report "West"

    Parameterized Subs do not appear in the Macros dialog.

  • A private helper

    Private Sub Helper() ' only callable from this module End Sub A Sub hidden from the Macros list

    Private keeps helpers out of the user's way.

Worth knowing

  • Name Subs with verbs: ImportSales, RefreshPivots.
  • Call one Sub from another by writing its name, with arguments after it.
  • Keep Subs short and let them call helpers.

Where it goes wrong

  • A Sub with arguments cannot be run from the Macros dialog or a button.
  • Missing End Sub is a compile error that stops every macro in the module.

Related

Learn the moves here — or let Wauvel run them on your numbers.

Meet your AI CFO →

One CFO-grade Excel tip a week

A short, practical email for finance operators — functions, shortcuts, and the moves that save an afternoon. Free, unsubscribe anytime.