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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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