substitute() multiple text

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I want to change "street" to "st" and "road" to "rd". I wrote substitute() to change "street" to "st". I also want to change the "road" to "rd". My question, do I need to create another substitute() to change "road" to "rd"?
Can I change both of them using one function instead of doing them twice. Thank you very much.

Book1
AB
1addressnew address
2100 main street100 main st
320 east road
488 west blv
5101 main street
621 east road
789 west blv
8102 main street
922 east road
1090 west blv
11103 main street
1223 east road
1391 west blv
14104 main street
1524 east road
Sheet1
Cell Formulas
RangeFormula
B2B2=SUBSTITUTE(A2,"street","st")
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi,

Yes, you'll need a SUBSTITUTE function for each word you want changed, it can not do arrays.
Just in case you may have street names like A16:A17 in my sample, add a space to the substitute fore & aft:

Book3.xlsx
AB
1addressnew address
2100 main street100 main st
320 east road20 east rd
488 west blv88 west blv
5101 main street101 main st
621 east road21 east rd
789 west blv89 west blv
8102 main street102 main st
922 east road22 east rd
1090 west blv90 west blv
11103 main street103 main st
1223 east road23 east rd
1391 west blv91 west blv
14104 main street104 main st
1524 east road24 east rd
16999 broadway road999 broadway rd
17111 roadward road111 roadward rd
Sheet771
Cell Formulas
RangeFormula
B2:B17B2=SUBSTITUTE(SUBSTITUTE(A2&" "," street "," st")," road "," rd")
 
Upvote 0
Hi,

Yes, you'll need a SUBSTITUTE function for each word you want changed, it can not do arrays.
Just in case you may have street names like A16:A17 in my sample, add a space to the substitute fore & aft:

Book3.xlsx
AB
1addressnew address
2100 main street100 main st
320 east road20 east rd
488 west blv88 west blv
5101 main street101 main st
621 east road21 east rd
789 west blv89 west blv
8102 main street102 main st
922 east road22 east rd
1090 west blv90 west blv
11103 main street103 main st
1223 east road23 east rd
1391 west blv91 west blv
14104 main street104 main st
1524 east road24 east rd
16999 broadway road999 broadway rd
17111 roadward road111 roadward rd
Sheet771
Cell Formulas
RangeFormula
B2:B17B2=SUBSTITUTE(SUBSTITUTE(A2&" "," street "," st")," road "," rd")

Hello jtakw can you please explain what is reason behind taking A2&" " instead of only A2
 
Upvote 0
A2&" " adds a space at the end of A2 like this (without quotes) "100 main street "
Now the SUBSTITUTE is replacing " street " (with space in front and after) with just " st"
This ensures we're substituting the stand alone word of " street " or " road " and it's not actually a part of a larger word like in my sample A16 & A17.

Without this step, A16:A17 would have resulted in:

999 brdway rd
111 rdward rd
 
Upvote 0
A2&" " adds a space at the end of A2 like this (without quotes) "100 main street "
Now the SUBSTITUTE is replacing " street " (with space in front and after) with just " st"
This ensures we're substituting the stand alone word of " street " or " road " and it's not actually a part of a larger word like in my sample A16 & A17.

Without this step, A16:A17 would have resulted in:

999 brdway rd
111 rdward rd

Thank you very much jtakw
now I understand your formula.(y)
 
Upvote 0
You're welcome, thanks for the feedback.
 
Upvote 0
you'll need a SUBSTITUTE function for each word you want changed, it can not do arrays.
That's not strictly true, although with the complexity of the array method it would need more than just 2 or 3 different words to substitute in order to justify using it.

The formula in column B is best guess for older versions I think it may also need to use T(IF({1},.. for some additional coercion but don't have a suitable version of excel installed for testing it.
Book1 (version 1).xlsb
ABCDEF
1addressregular excel (may need CSE confirmation)office 365 dynamic functionsReplaceWith
2100 main street100 main st100 main ststreetst
320 east road20 east rd20 east rdroadrd
488 west boulevard88 west blv88 west blvboulevardblv
5101 main street101 main st101 main st
621 east road21 east rd21 east rd
789 west boulevard89 west blv89 west blv
8102 main street102 main st102 main st
922 east road22 east rd22 east rd
1090 west boulevard90 west blv90 west blv
11103 main street103 main st103 main st
1223 east road23 east rd23 east rd
1391 west boulevard91 west blv91 west blv
14104 main street104 main st104 main st
1524 east road24 east rd24 east rd
16999 broadway road999 broadway rd999 broadway rd
17111 roadward road111 roadward rd111 roadward rd
Sheet7
Cell Formulas
RangeFormula
B2:B17B2=IFERROR(LOOKUP(2,1/SEARCH(" "&$E$2:$E$4&" ",A2&" "),SUBSTITUTE(A2&" "," "&$E$2:$E$4&" "," "&$F$2:$F$4)),A2)
C2:C17C2=LET(a,SUBSTITUTE(A2&" "," "&$E$2:$E$4&" "," "&$F$2:$F$4),FILTER(a,a<>A2&" ",A2))
 
Upvote 0
Ahh, yes, wrapping it inside LOOKUP to create the array, I use that method all the time, just didn't think of using it for SUBSTITUTE.
FYI, didn't need CSE for 2016, don't know about other older versions.

Can't speak for all the new functions after Excel 2016, don't have them, so don't know anything about them...
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,255
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top