Quick, clean, and to the point

LAMBDA strip characters

Excel formula: LAMBDA strip characters

This is an experimental formula to strip characters from text using a formula created with the LET and LAMBDA functions. In the example shown, the formula in F5, copied down, is:


Unlike the formula explained here, this formula is not recursive.


This is an experimental formula to strip characters from text. The experimental part is using character codes instead of regular characters as a way to make the formula case-sensitive, and providing a way to reverse the logic of the formula with the "keep" input parameter. Unlike the formula explained here, this formula is not recursive.

The formula takes four inputs:

text - the incoming text
chars - the characters to strip
rep - the character to replace stripped characters with
keep - strip or preserve chars (FALSE = strip, TRUE = preserve)

The keep parameter is a boolean that "flips" the behavior of the function from stripping characters to preserving characters.

In a nutshell, the SEQUENCE function is used to generate two arrays: one for the text, one for chars. In order to make the function case-sensitive, these arrays are composed not of characters but of the ASCII codes for each character.


The MID function extracts one character at a time, and CODE returns the numeric code. Inside the IF function, the logical test is:

ABS(keep-ISNUMBER(MATCH(textarr,chararr,0))) // logical test

The ISNUMBER and MATCH combo checks each code in textarr against codes in chararr. The ABS function is used as a way to reverse the logic of the formula. If keep is set to FALSE or zero, the ISNUMBER+MATCH logic is unchanged and chars are stripped. If keep is TRUE (or 1) the logic is reversed – chars are preserved and other characters are stripped.

LAMBDA version

To convert the formula to the LAMBDA function so that the formula can be named and reused throughout the workbook, the four input arguments are moved to the front, followed by the calculation, wrapped in LET:



LAMBDA is a beta function available in Excel 365 only.
Dave Bruns

Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.

Download 200+ Excel Shortcuts

Get over 200 Excel shortcuts for Windows and Mac in one handy PDF.