Excel like a finance pro.
VBA · Objects
User-defined worksheet functions
A Function in a standard module can be used in cells like any built-in function.
When to use it
A Function in a standard module can be called from a cell like a built-in function. Great for reusable business logic; limited because it can only return a value.
The code
- Code
=Double(A1) ' after writing Function Double in a module
Worked examples
Call from a cell
=Double(A1) ' after writing Function Double in a module → The function runs in the cell
The module must be a standard module.
Business rule
Function FiscalYear(d As Date) As Long FiscalYear = Year(d) + IIf(Month(d) >= 7, 1, 0) End Function → =FiscalYear(A2) gives the July-start fiscal year
Business rules in one place.
Volatile UDF
Application.Volatile → Placed inside a UDF, recalculates it on every change
For functions depending on things Excel cannot see.
Worth knowing
- UDFs cannot change other cells or formatting; they only return a value.
- UDFs cannot change other cells, formatting, or sheets; they only return.
- Pass ranges as Range parameters and read .Value inside.
- Errors inside a UDF show as #VALUE! in the cell.
Where it goes wrong
- Slow UDFs multiplied over thousands of cells drag the workbook.
- Users with macros disabled see #NAME?.
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.