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.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
try

=SUBSTITUTE(SUBSTITUTE(A1,"-"," - ",1)," "," ")
 
Last edited:
Upvote 0
Just for your examples, and Im assumed your text start on A2 :

=TRIM(SUBSTITUTE(LEFT(A2,MIN(FIND(CHAR(64+COLUMN($A$1:$W$1)),MID(A2,2,255)&(CHAR(64+COLUMN($A$1:$W$1)))))),"-"," - "))
 
Upvote 0
Think that will leave extra spaces.

should be ok, the 2nd sub replaces the double spaces with a single

just realised that it didn't shown correctly

Code:
=SUBSTITUTE(SUBSTITUTE(A1,"-"," - ",1),"  "," ")
 
Last edited:
Upvote 0
Paint -Topcoat 5600needtrailing####
Chemical- Bonderite Ready Setneedleading
Powder - Metco 100leave
Paint-Polyurethaneneedboth
it’s a start….
####
=IF(MID(C9,SEARCH("-",C9)-1,3)=" - ","leave",IF(MID(C9,SEARCH("-",C9),2)="- ","needleading",IF(MID(C9,SEARCH("-",C9)-1,2)=" -","needtrailing","needboth")))

<colgroup><col><col><col><col><col span="7"></colgroup><tbody>
</tbody>
 
Upvote 0

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