Changing part of string

Lavina

Board Regular
Joined
Dec 18, 2018
Messages
75
Hello guys,

I have a string in which i want to find a part, and once found replace it with a different string.

Say i have: abcd1abc

I want to find the part cd1 and replace it with cd2
Code:
Replace(ActiveCell, "cd1", "cd2")

But i want to replace text: cd(any number) with cd2.

And as far as i see wildcard cd* does not work in replace functions, and replacing without the number doesn't work either, how should i tackle this?
I can find position in string, make a cut off, then add the 3 strings together, but maybe there's something better?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
SEARCH takes a wild card.
Does the "cd#" occur only once? I played around with SEARCH and this will work although not particularly elegant.

Code:
=LEFT(A1,SEARCH("cd*",A1)+1)&"2"&RIGHT(A1,LEN(A1)-(SEARCH("cd*",A1)+2))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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