Explanation

TheLAMBDA functioncan be used to create custom, reusable functions in Excel.

This example illustrates a feature called recursion, in which a function calls itself.

Recursion can be used to create elegant, compact, non-redundant code.

Excel formula: LAMBDA count words

However, one disadvantage to recursive LAMBDA functions is that they are not easy to test.

In this way, the input parameter acts like a counter, counting down to zero.

Before the recursive call, theIF functionis used to check ifcharsis empty.

Excel formula: Strip non-numeric characters

If so, the formula returns the current value forstras a final result and exits.

The character to replace is provided by theLEFT function:

The value to use for replacement comes fromsub.

Oncecharshas been fully depleted (i.e.

Excel LAMBDA function

This will avoid the problem of words being combined when they are separated by punctuation only.

you’ve got the option to find more general information about the LAMBDA functionhere.

For example, =LEFT(“apple”,3) returns “app”.

Excel LEFT function

For example, =MID(“apple”,2,3) returns “ppl”.

LEN will also count characters in numbers, but number formatting is not included.

Excel MID function

Excel LEN function