Wauvel

Excel like a finance pro.

← The library

VBA · Objects

WorksheetFunction

Calls Excel functions like SUM, VLOOKUP, or MAX from VBA.

Very commonDifficulty 1150 · Proficient
Practice · 2 questions →

When to use it

Application.WorksheetFunction calls Excel functions from VBA: SUM, MAX, VLOOKUP, and most others. Application.Function (without WorksheetFunction) returns error values instead of raising errors.

The code

Code
total = Application.WorksheetFunction.Sum(Range("B2:B50"))

Worked examples

  • Sum

    total = Application.WorksheetFunction.Sum(Range("B2:B50")) The sum as a number

    Faster than a loop.

  • Safe VLOOKUP

    v = Application.VLookup(key, Range("A:C"), 3, False) If IsError(v) Then MsgBox "not found" A lookup that returns an error value rather than crashing

    The safe form for lookups.

  • Match

    pos = Application.WorksheetFunction.Match(key, Range("A:A"), 0) The position of a key; raises error 1004 if missing

    Wrap in On Error or use Application.Match.

Worth knowing

  • A failed lookup raises a runtime error here; use Application.VLookup (without WorksheetFunction) to get an error value instead.
  • Application.Match and Application.VLookup are the forgiving versions; test with IsError.
  • Not every function is available (no IF, no INDIRECT); write those in VBA.
  • Evaluate("=FORMULA") runs any formula text.

Where it goes wrong

  • A failed WorksheetFunction lookup raises runtime error 1004.
  • Range arguments must be ranges or arrays, not addresses as text.

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.