To simply combine them you can place them all together like this:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"_AB","_"),"_CD","_"),"_EF","_"),"_40K",""),"_60K",""),"_S_","_"),"_","-")
(note that this may pass the older Excel limit of 7 nested statements. I'm testing in Excel 2010
Another way to do it is by utilizing Left and Right functions.
This assumes that the changing data on the end is always present and is 8 characters long
=SUBSTITUTE(LEFT(A2,LEN(A2)-8),"_","-")
This will achieve the same resulting string
If the string doesn't always end with 8 characters that you want to strip off you can search for the "_S" and get the current location. Try this:
=SUBSTITUTE(LEFT(A2,FIND("_S",A2,1)),"_","-")
Answer from Automate This on Stack OverflowTo simply combine them you can place them all together like this:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"_AB","_"),"_CD","_"),"_EF","_"),"_40K",""),"_60K",""),"_S_","_"),"_","-")
(note that this may pass the older Excel limit of 7 nested statements. I'm testing in Excel 2010
Another way to do it is by utilizing Left and Right functions.
This assumes that the changing data on the end is always present and is 8 characters long
=SUBSTITUTE(LEFT(A2,LEN(A2)-8),"_","-")
This will achieve the same resulting string
If the string doesn't always end with 8 characters that you want to strip off you can search for the "_S" and get the current location. Try this:
=SUBSTITUTE(LEFT(A2,FIND("_S",A2,1)),"_","-")
No need to use VBA anymore for this! Super simple formula now!
=REDUCE(A1,2:
6,LAMBDA(a,b,SUBSTITUTE(a,b,OFFSET(b,0,1))))
Where A1 is the target cell to replace text b2:b6 is where the keywords are stored (texts to be replaced) c2:c6 (referenced by the offset) is where the replacing texts are stored
Credit: Chandoo
Replace multiple specific pieces of text in a cell
excel - Can you use SUBSTITUTE for many values without nesting? - Stack Overflow
How can I replace multiple string at once in Excel? - Stack Overflow
Replace multiple text strings in a phrase without a recursive lambda (per se') using REDUCE()
I want to use substitute with {".","!",";"} etc to remove the common non-alphanumeric characters. I know I can nest a bunch of substitute formulas together, but is there a way to do this by passing an array of symbols into the formula instead?
Update 27-4-'22:
Since LAMBDA() and it's helper functions have now been released to the production versions of ms365, one could use REDUCE():
=TRIM(REDUCE(A1,{"Target","Walmart","CVS"},LAMBDA(a,b,SUBSTITUTE(a,b,""))))
Or, even try:
=TEXTJOIN(" ",,TEXTSPLIT(A1,{" ","Target","Walmart","CVS"}))
But, be aware of possible false positives, however SUBSTITUTE() and TEXTSPLIT() are both case-sensitive so for these proper words it seemed to work out fine. To counter false positives, 1st change spaces to tripple spaces for example and go from there (or use the old answer which is still valid). Another option is to nest FILTER():
=TEXTJOIN(" ",,REDUCE(TEXTSPLIT(A1," ",,1),{"Target","Walmart","CVS"},LAMBDA(a,b,FILTER(a,a<>b))))
Old Answer (Still valid since it avoids false positives):
I guess I'd go with a "Yes it's possible, but..." answer. It may be a stretch but I noticed you haven't used any punctuation which lead me to believe we can split a string on the space and filter out the unwanted parts that way, piecing back together the wanted parts:

Formula in A2:
=TEXTJOIN(" ",,FILTERXML("<t><s>"&SUBSTITUTE(A1," ","</s><s>")&"</s></t>","//s["&TEXTJOIN(" and ",,".!= '"&B1:B3&"'")&"]"))
Now you can add as many values to your range of unwanted strings without further adaptation to your formula.
- Note that this does require Excel 2019 or later for the
TEXTJOIN()to work. With Excel 2019 you'd also need to confirm through CtrlShiftEnter. - Also note that this will need some adaptation the minute you start using punctuation.
- A last remark is that
FILTERXML()is case-sensitive.
There is no way with SUBSTITUTE outside of nesting to do what is wanted. In the future LAMBDA will be an option.
For now and for backwards compatibility, here is a UDF that creates a function that takes many inputs and replaces them with the desired output.
It uses a param array so one can also create individual replacements:
Function SUBALL(str As String, ParamArray arr() As Variant) As String
Dim i As Long
For i = LBound(arr) To UBound(arr) Step 2
Dim rngarr As Variant
rngarr = arr(i)
If UBound(arr) > i Then
Dim rpArr As Variant
rpArr = arr(i + 1)
Else
Dim df As Boolean
df = True
End If
If TypeName(rngarr) = "String" Then
If df Then
str = Replace(str, rngarr, "")
Else
str = Replace(str, rngarr, rpArr)
End If
Else
Dim j As Long
For j = LBound(rngarr, 1) To UBound(rngarr, 1)
If df Then
str = Replace(str, rngarr(j, 1), "")
Else
str = Replace(str, rngarr(j, 1), rpArr(j, 1))
End If
Next j
End If
Next i
SUBALL = str
End Function
It defaults to a replace of ""
So in this instance:
=SUBALL(A1,H1:H3)

But we can also do where we specify the output:
=SUBALL(A1,H1:H3,I1:I3)

Or we can put the options as strings in the formula itself with their desired replacements:
=SUBALL(A1,"Target","MyVal","Walmart","","CVS","Long Receipt Place")

As with all UDF, there are some rules that must be followed. The pairs must have the same number of arguments. You CANNOT do:
=SUBALL(A1,H1:H3,"Word")
It will fail. But:
=SUBALL(A1,H1:H3,{"Word";"Word";"Word"})
Will work.

With SCAN and LAMBDA:
=LET(rpl,H1:H3,str,A1,INDEX(SCAN(str,rpl,LAMBDA(a,b,SUBSTITUTE(a,b,""))),COUNTA(rpl)))

If we want to replace words with other words we can use:
=LET(orig,H1:H3,rpl,I1:I3,str,A1,cnt,COUNTA(rpl),INDEX(SCAN(str,SEQUENCE(cnt),LAMBDA(a,b,SUBSTITUTE(a,INDEX(orig,b),INDEX(rpl,b)))),COUNTA(rpl)))

The way you described your requirement is best written out via REDUCE(), a lambda-related helper function and recently announced to be in production:
=REDUCE("9528",SEQUENCE(10),LAMBDA(x,y,SUBSTITUTE(x,MID("1234567890",y,1),MID("abcdefghij",y,1))))
Needless to say, this would become more vivid when used with cell-references:

Formula in A3:
=REDUCE(A1,SEQUENCE(LEN(B1)),LAMBDA(x,y,SUBSTITUTE(x,MID(B1,y,1),MID(C1,y,1))))
Another, more convoluted way, could be:
=LET(A,9528,B,1234567890,C,"abcdefghij",D,MID(A,SEQUENCE(LEN(A)),1),CONCAT(IFERROR(MID(C,FIND(D,B),1),D)))
Or, as per the sceenshot above:
=LET(A,A1,B,B1,C,C1,D,MID(A,SEQUENCE(LEN(A)),1),CONCAT(IFERROR(MID(C,FIND(D,B),1),D)))
Function Multi_Replace(Original As String, Search_Text As String, Replace_With As String) As String
'intEnd represents the last character being replaced
Dim intEnd As Long: intEnd = WorksheetFunction.Min(Len(Search_Text), Len(Replace_With))
'necessary if Search text and replace text are different lengths;
Dim intChar As Long 'to track which character we're replacing
'Replace each character individually
For intChar = 1 To intEnd
Original = Replace(Original, Mid(Search_Text, intChar, 1), Mid(Replace_With, intChar, 1))
Next
Multi_Replace = Original
End Function
Saw this technique about using REDUCE in a recursive type role and thought I'd share an easy use case.
Using REDUCE()=LET(phrase,A1,
text,A4:A6,
replwith,B4:B6,
REDUCE(phrase,SEQUENCE(ROWS(text)),LAMBDA(newphrase,next,SUBSTITUTE(newphrase,INDEX(text,next),INDEX(replwith,next)))))
Phrase is the starting text string.
Text is an array of words (case sensitive) you want replaced in Phrase.
replwith is an equal array of text strings you want to to use as the substitution text.
REDUCE starts with phrase and then iterates n times where n is the length of the text array. Each time it substitutes one element of the text array with the corresponding element of the replwith array. The result after n iterations is newphrase.
in cell b1: =SUBSTITUTE(A1,"--","-")
you can then copy this across to c1, d1, e1 etc. Each further cell to the right will have one less - than the previous. Add columns until all hyphens are dealt with.
This way if you add a new row where there are more hyphens than in previous rows, you can just make extra columns, instead of changing the formula which gets messy.
A tiny trick for a single cell solution. If A1 does not contain any spaces, in A2 enter:
=SUBSTITUTE(TRIM(SUBSTITUTE(A1,"-"," "))," ","-")
This can handle any number of consecutive dashes:

If A1 does contain some spaces, a slightly more complex formula will be required!
EDIT#1:
If A1 contains spaces, they must first be "protected" with something like:
=SUBSTITUTE(A1," ",CHAR(1))
and then, in the outer-most substitution, the "protection" must be removed. The final formula is:
=SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(A1," ",CHAR(1)),"-"," "))," ","-"),CHAR(1)," ")
I will admit that this is pretty ugly, but it can handle an unlimited number of dashes.