A LAMBDA can call itself — once you name it — to loop without VBA. Recursion handles tasks like cleaning a list of characters, walking a tree, or repeating an operation a variable number of times.
chars is empty — the base case that stops the recursion.
The example
Strip several unwanted characters in one named function.
| A | B | |
|---|---|---|
| 1 | Input | Cleaned |
| 2 | (555) 123-4567 | 5551234567 |
The formula
A LAMBDA that calls itself:
How it works
Recursion needs a name and a base case:
- Define the LAMBDA in Name Manager with a name (e.g.
RemoveChars) — recursion needs the name to refer to itself. - Include a base case:
IF(chars="", txt, …)stops when there’s nothing left to do. - In the recursive branch, do one step and call the name again with reduced input.
- Call it on the sheet like any function:
=RemoveChars(A2, "()- ").
Always give it a base case. Without a stopping condition, a recursive LAMBDA loops until Excel runs out of memory and returns an error. Test on small inputs first, and watch performance on long lists — sometimes REDUCE or SCAN is a cleaner loop.
Try it: interactive demo
Strip these characters from the text.
Variations
Factorial
Classic recursion:
Repeat N times
Loop a transform:
REDUCE instead
Often simpler than recursion:
Pitfalls & errors
Must be named. A LAMBDA can only recurse if it has a name to call — an anonymous inline LAMBDA can’t refer to itself.
Base case is mandatory. No stopping condition = infinite recursion = error.
Watch performance. Deep recursion over long inputs can be slow; consider REDUCE/SCAN for list loops.
Practice workbook
Frequently asked questions
How do I make a recursive LAMBDA in Excel?
Why does my recursive LAMBDA error?
Is recursion the only way to loop in Excel?
Stop fighting formulas. Learn them in a day.
This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.
See the Formulas & Functions Class