![]() If the LAMBDA function is not available in your Excel, nothing prevents you from creating a similar function with VBA. The functions work in all versions of Excel As soon as the last character has been processed, the formula returns string it its present form and exits.įor the detailed formula break down, please see Recursive LAMBDA to remove unwanted characters. ![]() If the chars string is not empty (chars""), the function calls itself. Before each recursive call, the IF function checks the remaining chars. In essence, the RemoveChars function loops through the list of chars and removes one character at a time. To eliminate special characters from A2, the formula is: =LAMBDA(string, RemoveChars(string, "0123456789"))īoth of the above functions are super-easy to use as they require just one argument - the original string. =LAMBDA(string, RemoveChars(string, remove numbers from text strings, we've created one more function named RemoveNumbers: To delete special characters, we've created a custom function named RemoveSpecialChars: To delete a predefined set of characters from multiple cells, you can create another LAMBDA that calls the main RemoveChars function and specify the undesirable characters in the 2 nd parameter. And due to support for dynamic arrays, the formula spills automatically into all the referenced cells: ![]() Since the formula is entered only in the top-most cell, you needn't worry about locking the cell coordinates - a relative reference (D2) works fine in this case. To clean multiple cells with a single formula, supply the range A2:A6 for the 1st argument: The address of the cell containing the special characters is locked with the $ sign ($D$2) to prevent the reference from changing when coping the formula to the below cells.Īnd then, we simply drag the formula down and have all the characters listed in D2 deleted from cells A2 through A6:.In D2, characters are listed without spaces, unless you wish to eliminate spaces too.To remove those characters from A2, the formula is:įor the formula to work correctly, please take notice of the following things: Can be represented by a text string or a cell reference.įor convenience, we input unwanted characters in some cell, say D2. String - is the original string, or a reference to the cell/range containing the string(s).Once the function gets a name, you can refer to it like any native formula.įrom the user's viewpoint, the syntax of our custom function is as simple as this: The parameters will be displayed when you type a formula in a cell.įor the detailed instructions, please see How to name a custom LAMBDA function. Optionally, enter the description of the parameters in the Comments box.In the Refers to box, paste the above formula.In the Name box, enter the function's name: RemoveChars.For this, press Ctrl + F3 to open the Name Manager, and then define a New Name in this way: To be able to use this function in your worksheets, you need to name it first. =LAMBDA(string, chars, IF(chars"", RemoveChars(SUBSTITUTE(string, LEFT(chars, 1), ""), RIGHT(chars, LEN(chars) -1)), string)) Below, I'll illustrate the concept with a couple of practical examples.Ī custom LAMBDA function to remove unwanted characters is as follows: This new function is named LAMBDA, and you can find full details about it in the above-linked tutorial. The solution only works in Excel for Microsoft 365Īs you probably know, Excel 365 has a special function that enables you to create your own functions, including those that calculate recursively. The next example demonstrates a more compact and elegant solution. Nested SUBSTITUTE functions work fine for a reasonable number of characters, but if you have dozens of characters to remove, the formula becomes too long and difficult to manage. The same can be done with the help of the CHAR function, where 161 is the character code for "¡" and 191 is the character code for "¿": SUBSTITUTE(SUBSTITUTE(SUBSTITUTE( cell, char1, ""), char2, ""), char3, "")įor example, to eradicate normal exclamation and question marks as well as the inverted ones from a text string in A2, use this formula:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |