Need Help Adding Spaces

dwgnome

Active Member
Joined
Dec 18, 2005
Messages
441
Need assistance in adding a space after the first word and before the dash and one space after the dash. All strings are in one cell. For example Paint-Primer GX becomes Paint - Primer GX by adding a space on either side of the dash. Sometimes a space will already be on one side of the dash but not the other. So here are the possible scenarios:

Paint -Topcoat 5600 (need just one space after the dash)
Chemical- Bonderite Ready Set (need a space before the dash)
Powder - Metco 100 (no adjustment necessary)
Paint-Polyurethane (need space on both sides of the dash)

Also, there may be other dashes later in the string, so just need the first occurrence to be adjusted.

Excel 2003.
 
Thank you all for replying. You saved me a lot of time not having to manually adjust the spacing. I ended up using gaz_chops version as it is concise and does the job perfectly. In fact I forgot to mention that if there is more than one space before or after, that those should be removed. This formula does that while AlanY works for most cases, however it does not remove the extra spaces if any occur.

Azumi, not sure what your first formula is doing, but it seems to chop off rest of string on some of them as I copy down. My data actually starts at D20 so not sure how to deal with COLUMN range or why I would need that since I am only interrogating the cell to the left. Of course your second version is similar to and works like gaz_chops' version.

oldbrewer, thanks again for chiming in. Very interesting approach, but not wanting to actually result in a text statement, just make the change itself.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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