Using Lambda for Iterations or Recursion

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

Watch the video below:

Using Lambda Function for Recursion

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

  1. Syntax of the function. For example: =LAMBDA([parameter1, parameter2, …,] calculation).
  2. 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.
  3. 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.
  4. We call a lambda function. We call a lambda function the same manner we call native functions in Excel like PMT, SUM, Average, etc.
  5. 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.

Recursion Using lambda
Recursion Using lambda


Published by

Dinesh Kumar Takyar

Welcome to exceltrainingvideos.com! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: http://youtube.com/familycomputerclub For a structured Excel VBA training course online you can visit: https://www.youtube.com/excelvbaonline

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.