Excel like a finance pro.
VBA · Syntax
Optional arguments
Parameters a caller can leave out, with a default value.
When to use it
Optional parameters can be left out by the caller and take a default value. IsMissing tests Variants that were omitted.
The code
- Code
Function Tax(amount As Double, Optional rate As Double = 0.07) As Double
Worked examples
Default value
Function Tax(amount As Double, Optional rate As Double = 0.07) As Double Tax = amount * rate End Function → Tax(100) uses 7%; Tax(100, 0.1) overrides
Defaults in the signature.
Optional object
Sub Log(msg As String, Optional ws As Worksheet) If ws Is Nothing Then Set ws = ActiveSheet → An optional object tested with Is Nothing
Objects default to Nothing.
IsMissing
Sub Run(Optional v As Variant) If IsMissing(v) Then ... → IsMissing works only for Variants
The Variant form.
Worth knowing
- Optional parameters must come after required ones.
- ParamArray takes any number of arguments as an array.
- Named arguments (rate:=0.1) skip earlier optionals.
Where it goes wrong
- IsMissing is always False for typed optionals; they get their default.
- Optional with no default gives 0 or "" for typed parameters.
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.