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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,215,193
Messages
6,123,566
Members
449,108
Latest member
rache47

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