A Macro to delete all but one comma

M

Madchatthew

Hello,

I thank anyone in advance who can help me with this. I have a word document that I need to delete a bunch of comma's. It kinda looks like this.

data,,data,,,,,data
data1,data,,data
data2,,,,data,,,,data

I would like a macro that will delete all but one comma from each column per say. So the final result would be:

data,data,data
data1,data,data
data2,data,data

I am not sure how I would even start to do something like that but believe it is possible. Thank you very much in advance and it will save days of work. Thank you

Madchatthew
 
G

Gidget

use the edit replace optio

firs
you want to tell it to replace ,, (two commas) with ,,,(three commas) -

then you tell it to replace ,, (two commas) with , (one comma
You keep telling it to replace the ,, with , until it cannot find anymore

Sounds crazy but it works... try it.
 
M

Madchatthew

Sweet thanks...I will give it a try...sounds to simple to work...cool

----- Gidget wrote: -----

use the edit replace option

first
you want to tell it to replace ,, (two commas) with ,,,(three commas) -

then you tell it to replace ,, (two commas) with , (one comma)
You keep telling it to replace the ,, with , until it cannot find anymore.

Sounds crazy but it works... try it.
 
M

Madchatthew

Hey Gidget,

That worked perfect. Literally days saved. Thanks alot. It always amazes me how the answer is right in front of anyones' face...thanks again.

Madchatthew

----- Gidget wrote: -----

use the edit replace option

first
you want to tell it to replace ,, (two commas) with ,,,(three commas) -

then you tell it to replace ,, (two commas) with , (one comma)
You keep telling it to replace the ,, with , until it cannot find anymore.

Sounds crazy but it works... try it.
 
S

Suzanne S. Barnhill

The first step is unnecessary, however. Just start by replacing two with one
and continue till no more replacements are made.
 
G

Graham Mayor

Even quicker for next time is to use a wildcard search.
Replace
(,),{1,}
with
\1
This will remove all the extras in one pass.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top