Forum Discussion
Formula to edit part of a text in one cell based on an values in another cell
- Jul 17, 2022
In attached file, a different approach for TEXT_SPLIT:
=LAMBDA(Value,Delimiter, LET( Positions, LAMBDA(String,Delim,Sequence, LET( k, SCAN(0,Sequence, LAMBDA(acc,s, IF(MID(String,s,1)=Delim, acc+s, 0))), FILTER(k, k > 0) ) ), Seq, SEQUENCE(LEN(Value)+1), Start, Positions(Delimiter & Value, Delimiter, Seq), End, Positions(Value & Delimiter, Delimiter, Seq), MID(Value, Start, End-Start) ) )
Updated previous Result formula to account for nothing to return and added a couple of other options that avoid spliting A2 (better IMHO)
in D2:
=LET( value, TEXT_SPLIT(A2,";"), TEXTJOIN(";",,FILTER(value,ISNA(XMATCH(value,TEXT_SPLIT(B2,";"))),"")) )
in F2:
=LET( Removed, REDUCE(A2&";",TEXT_SPLIT(B2,";"), LAMBDA(value,arr, SUBSTITUTE(value,arr&";","")) ), IF(LEN(Removed) = 0, "", LEFT(Removed, LEN(Removed)-1)) )
in H2:
=LET( Removed, REDUCE(LOWER(A2)&";",TEXT_SPLIT(LOWER(B2),";"), LAMBDA(value,arr, SUBSTITUTE(value,arr&";","")) ), IF(LEN(Removed) = 0, "", LEFT(Removed, LEN(Removed)-1)) )
In attached file, a different approach for TEXT_SPLIT:
=LAMBDA(Value,Delimiter,
LET(
Positions, LAMBDA(String,Delim,Sequence,
LET(
k, SCAN(0,Sequence, LAMBDA(acc,s, IF(MID(String,s,1)=Delim, acc+s, 0))),
FILTER(k, k > 0)
)
),
Seq, SEQUENCE(LEN(Value)+1),
Start, Positions(Delimiter & Value, Delimiter, Seq),
End, Positions(Value & Delimiter, Delimiter, Seq),
MID(Value, Start, End-Start)
)
)
Updated previous Result formula to account for nothing to return and added a couple of other options that avoid spliting A2 (better IMHO)
in D2:
=LET(
value, TEXT_SPLIT(A2,";"),
TEXTJOIN(";",,FILTER(value,ISNA(XMATCH(value,TEXT_SPLIT(B2,";"))),""))
)
in F2:
=LET(
Removed, REDUCE(A2&";",TEXT_SPLIT(B2,";"),
LAMBDA(value,arr, SUBSTITUTE(value,arr&";",""))
),
IF(LEN(Removed) = 0, "", LEFT(Removed, LEN(Removed)-1))
)
in H2:
=LET(
Removed, REDUCE(LOWER(A2)&";",TEXT_SPLIT(LOWER(B2),";"),
LAMBDA(value,arr, SUBSTITUTE(value,arr&";",""))
),
IF(LEN(Removed) = 0, "", LEFT(Removed, LEN(Removed)-1))
)
- githinmg99Jul 18, 2022Copper Contributor
Lorenzo thanks again. My TEXT_SPLIT formula is still not getting recognized and is giving me the #NAME? error. I have copied the same formula to my name manager. Did I miss out anything?
- SergeiBaklanJul 18, 2022Diamond Contributor
On which Excel version you are ? Perhaps SCAN() is not available. Alternatively
textSplit_ = LAMBDA( str, sep, LET( n, LEN(str) - LEN(SUBSTITUTE(str,sep, "") ) + 1, fakeSep, UNICHAR(9999), strWithFakeSep, SUBSTITUTE(str, sep, fakeSep, n-1), fakeSepPosition, FIND( fakeSep, strWithFakeSep ), head, LEFT( strWithFakeSep, fakeSepPosition - 1 ), tail, RIGHT(strWithFakeSep, LEN(strWithFakeSep) - fakeSepPosition ), IF( n=1, IF(str = "", "", str), IF( SEQUENCE(,n) < n , textSplit_( head , sep ), tail ) ) ))
- LorenzoJul 18, 2022Silver Contributor
I'm at lost. In your reply to HansVogelaar you said you were working with Excel Online where LAMBDA, SCAN, REDUCE... functions are available
The 1st version of TEXT_SPLIT I shared did not involve SCAN and you already reported a #NAME? error
IMHO it's more than time to clarify the exact version you're working with - Thanks