A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi,
Enter this formula in cell D2
=REDUCE(C2,$A$2:$A$4,LAMBDA(a,b,SUBSTITUTE(a,b,XLOOKUP(b,$A$2:$A$4,$B$2:$B$4))))
Hope this helps.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In col A, I have
old1
old2
old3
...
In col B, I have
new1
new2
new3
...
In D1, I have:
=substitute(C1,A1,B1)
so that text entered in C1 is shown in D1 with old1 substituted by new1.
But, for that single cell C1, I want to apply every listed sub. E.g., Entering "id old1 id old3" in C1 yields "id new1 id new3" in D1
Longform, one method for this would be D1:
=substitute(substitute(substitute(C1,A1,B1),A2,B2),A3,B3)
for the first 3 substitutions. How can I implement this effect efficiently, for however long the substitution list is, whether by generating a nested substitution like that, or with a different method — but just using sheet formulas, without using a macro please.
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi,
Enter this formula in cell D2
=REDUCE(C2,$A$2:$A$4,LAMBDA(a,b,SUBSTITUTE(a,b,XLOOKUP(b,$A$2:$A$4,$B$2:$B$4))))
Hope this helps.
You can use REDUCE together with LAMBDA to apply each substitution in sequence. For example, if your substitutions are in A1 and B1, and the original text is in C1, try:
=LET(old,FILTER(A1,A1<>""),new,FILTER(B1,A1<>""),REDUCE(C1,SEQUENCE(ROWS(old)),LAMBDA(txt,i,SUBSTITUTE(txt,INDEX(old,i),INDEX(new,i)))))
This first removes any unused rows from the substitution list and then applies each old/new pair one after another. Therefore, if C1 contains id old1 id old3, with old1/new1 and old3/new3 in columns A and B, the result will be id new1 id new3. You can increase A1 and B1 as needed, or preferably convert the substitution list to an Excel Table if it will continue growing.
[EDITED] Has a solution.