How to use Lambda in Excel for iterative or recursive functions without VBA.

Watch the video below:

In my last video on Lambda functions I showed you how to create a Lambda function from scratch. It involved the following steps:

- Syntax of the function. For example: =LAMBDA([parameter1, parameter2, …,] calculation).
- A parameter is a value that we wish to pass to the function, such as a cell reference, string, or number. We can use up to 253 parameters.
- Calculation: This argument is required. It represents the formula we want to execute like multiplying two numbers and return the result of the function. It is the last argument and it must return a result.
- We call a lambda function. We call a lambda function the same manner we call native functions in Excel like PMT, SUM, Average, etc.
- We name a lambda function using the Name Manager

If we create a LAMBDA called **ProductOfTwoNumbers** for example, we can call **ProductOfTwoNumbers** within the definition of **ProductOfTwoNumbers**. This was earlier possible in Excel through VBA.

In the REMOVECHARS Lambda function, we have used the two text functions LEFT and RIGHT and the function SUBSTITUTE as shown below:

=LAMBDA(textString, illegalChars, IF(illegalChars=””, textstring, REMOVECHARS(

SUBSTITUTE(textString, LEFT(illegalChars, 1), “”), RIGHT(illegalChars, LEN(illegalChars)-1))))

We notice that in the definition of REMOVECHARS, there is a reference to REMOVECHARS. The IF statement tells us that if there are no more illegal characters then return the input String else remove each occurrence of the leftmost character in ‘illegalChars’. Recursion begins with the request to call REMOVECHARS again with the updated string, and the rest of ‘illegalChars’. This means it will keep calling itself until it has read every character to be removed.