Automatically replace a group of characters with a specific character

merQrey

New Member
Joined
Feb 22, 2014
Messages
9
Hello dear excel masters
smile.gif
hope someone can assist me with this query. i have a list of product codes that have certain characters that i would like replaced to the "_" character. this following items i would like to automatically be changed to the _ (underscore) character
"."
"/"
"+"
" " "
" space character "

so for instance if i have the following product code
"NUA-MPRO1866R/16G"

i would like it to be "NUA-MPRO1866R_16G"

some product codes have multiple characters that i would like changed
example as follows
"VORTEX V4 404/WU"

this should become "VORTEX_V4_404_WU"

can this be done??
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
This solution looks awkward and ugly but is necessary because REPLACE and SUBSTITUTE won't rationalise the array of search values (i.e., the ".", the "+", etc.) to a single result. I hope this isacceptable for your purposes, otherwise VBA will be required.

Simply nest each substitute construction inside another for as many values you wish to substitute. I had trouble understanding what you meant by the three """ so could you please elaborate?

P.S. Please don’t type posts in all lower case (especially the pronoun I) – it’s really frustrating to read and looks entirely unprofessional. Thanks tons.

AB
1NUA-MPRO1866R/16GNUA-MPRO1866R_16G
2VORTEX V4 404/WUVORTEX_V4_404_WU

<tbody>
</tbody>
Sheet12

Worksheet Formulas
CellFormula
B1=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,".","_"),"/","_"),"+","_")," ","_"),"""","_")
B2=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,".","_"),"/","_"),"+","_")," ","_"),"""","_")

<tbody>
</tbody>

<tbody>
</tbody>

<strike></strike>
 
Upvote 0
You could simply use FIND/REPLACE, and replace ALL (so you would need to do one replace for each different character). That doesn't involve any formulas.

If you want it done automatically, you can use the Macro Recorder and record yourself performing those steps, and you will get the code you need.

If you wanted to get really fancy in VBA, you could set up an array with your different values and loop through them, but for only 5 characters, it won't save much (though the code is a bit shorter). You may also need to add some error handling, essentially telling it to ignore errors (like if it does not find any matches).
 
Upvote 0
P.S. Please don’t type posts in all lower case (especially the pronoun I) – it’s really frustrating to read and looks entirely unprofessional. Thanks tons.
Not nearly as bad as typing in all caps. Personally, I don't have any issue with it, but I guess we all have our pet peeves, eh?
 
Upvote 0
It's not really a peeve nor a pet peeve. Requiring no less from others than of myself, I think we all owe one another the courtesy of being clear, precise, accurate and correct in our communications. Developing habits of excellence can only serve to improve us all. Heck, that's why we participate in this awesome forum --- to help one another improve --- with myself being the most gracious beneficiary of everyone's efforts.

TYPING IN ALL CAPS OUGHT TO BE MADE ILLEGAL, PUNISHABLE BY BANISHMENT FROM THE INTERNET.
 
Last edited:
Upvote 0
Thank you kindly for your assistance DRSteele :)
I take heed of your note and do apologize for any inconvenience caused.
Thank you once again for your assistance, greatly appreciated :)
 
Upvote 0
You're most welcome. No apologies necessary...I shouldn't have mentioned it. I'm happy to help.
 
Upvote 0

Forum statistics

Threads
1,216,081
Messages
6,128,695
Members
449,464
Latest member
againofsoul

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