how to remove spaces before commas

bulletproof

New Member
Joined
Jun 22, 2011
Messages
26
hi guys.

sorry for being a newb but would any of you
would be kind enough to show me a formula for:

what I have:

last name , first name
last name, first name
last name , first name

what i need to do:

last name, first name
last name, first name
last name, first name


as you can see, some of those last names have spaces before the commas. I need to get those spaces out.
I understand that the TRIM function only deals with the spaces before
and after and the trailing ones.

I tried to search for it, though not quite successful in my chosen keywords.

I'm just an old dog trying to learn new tricks from excel.

thanks much.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
In case there may be more than one space preceding the comma you could use the following:

=SUBSTITUTE(TRIM(A1)," ,",",")
 
Upvote 0
In case there may be more than one space preceding the comma you could use the following:

=SUBSTITUTE(TRIM(A1)," ,",",")

I tried this and it works! HAHA!!!

thanks Richard, Vog and Andrew!

you guys are lifesavers!:)


additional question though:

how should the function look like if i need to
put in a space after the comma, like:

last name,first name to last name, first name?
 
Last edited:
Upvote 0
That would be:

=TRIM(SUBSTITUTE(A1," ,",", "))

HMMM...

it didn't quite do what I was expecting.
almost same result with:
=SUBSTITUTE(TRIM(A1)," ,",",")

here's my dilemma:

i have data coming from 2 sources with no common identifier
to begin with.

i have to rely on the names since both sources uses last name-first name
arrangement.
one source i cannot/i'm not allowed to edit/change.
the other, i can edit.

the data source i can edit is cumbersome.
some layout of the names are:

last name , first name
last name,first name
lastnamefirstname
last name ,first name
last name ,first name
last name, first name

when all i need them to be is:

last name, first name

is this possible?
or can one or combined functions do this?

thanks again for all your help, andrew :pray:

sorry for not explaining clearly on my first post.
I should have explained it.
I was thinking I could do the rest without bothering you guys here
but it's taking off a chunk of my time already, really must be getting old... :(
 
Upvote 0
^

NICE!

thanks Andrew.

any thoughts on how to fix that

last namefirst name
to
last name, first name

even if i use a function just to do it on a separate column?

thanks again :pray:
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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