Remove Spaces Before a Comma Only

lucolem

New Member
Joined
Sep 7, 2012
Messages
12
Hello all,
I'm looking for a formula to remove a space, if it exists, before a comma. For instance, I need "Golden Retriever,Dog" to be "GoldenRetriever,Dog". I need it to only remove the space before the comma because there will be spaces after the comma that need to stay there. And there won't always be a space; don't know if that makes a difference.

Any ideas? Thanks!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
If you can't use a formula, press ctrl+f, select replace. In "Find What", type: , (make sure you put a space before the comma). In "Replace With", just type: , (no space before the comma).
 
Upvote 0
Try =SUBSTITUTE(LEFT(A1,FIND(",",A1))," ","")&(RIGHT(A1,LEN(A1)-FIND(",",A1)))

Where A1 is the cell the text is in
 
Upvote 0
Why not substitute just the 1st occurance?

=SUBSTITUTE(A1," ,",",",1)
 
Last edited:
Upvote 0
I'm not sure, but that one didn't seem to work for me.

I am curious... in what way did it not seem to work for you. Given your description of your data, the formula works fine for me in my tests... and it is a heck of a lot more efficient to use a formula with only one function call than it is to use one with five function calls.
 
Upvote 0
Well, I'm guessing if all the spaces were right before the comma, it would have worked. But I used the Find & Replace for those and was looking only for a formula to remove spaces from the double names before the comma. In my data, the space wasn't beside the comma - I needed "Golden Retriever,Dog" to be "GoldenRetriever,Dog" so the GoldenRetriever was one word, not 2. I'm sorry if I didn't express what I needed correctly! :)


I am curious... in what way did it not seem to work for you. Given your description of your data, the formula works fine for me in my tests... and it is a heck of a lot more efficient to use a formula with only one function call than it is to use one with five function calls.
 
Upvote 0
Well, I'm guessing if all the spaces were right before the comma, it would have worked. But I used the Find & Replace for those and was looking only for a formula to remove spaces from the double names before the comma. In my data, the space wasn't beside the comma - I needed "Golden Retriever,Dog" to be "GoldenRetriever,Dog" so the GoldenRetriever was one word, not 2. I'm sorry if I didn't express what I needed correctly! :)

Oh, the space before the comma, but not next to the comma. Then try just changing the thing being substituted from a space-comma to just a space and replace it with the empty string instead of a comma in HOTPEPPER's formula...

=SUBSTITUTE(A1," ","")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,021
Messages
6,128,319
Members
449,440
Latest member
Gillian McGovern

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