How do I add a comma between a range of cells?

G

Guest

Example: I have cells A1 through A70 with data in each cell in the following
format 123-03-123. I need a sting of text returned that will combine the
cells separated by a comma.

Example: 123-34-234,234-23-234,345-23-123, etc...

I need to be able to copy and paste the string in to a websearch that
specifies "separated by commas no spaces"

I know there has to be a simple way to do that but I am a rookie in Excel :(

Thanks for all your help...

Chris
 
G

Gord Dibben

With 70 cells I would use a user defined function.

Function ConCatRange(CellBlock As Range) As String
Dim cell As Range
Dim sbuf As String
For Each cell In CellBlock
If Len(cell.text) > 0 Then sbuf = sbuf & cell.text & ","
Next
ConCatRange = Left(sbuf, Len(sbuf) - 1)
End Function

After concatenating the range using =ConCatRange(A1:A70)

copy/paste special>values.


Gord Dibben MS Excel MVP

On Tue, 19 Jun 2007 15:03:41 -0700, AZ ChrisD <AZ
 
G

Guest

That did it...

Thanks a bunch

Gord Dibben said:
With 70 cells I would use a user defined function.

Function ConCatRange(CellBlock As Range) As String
Dim cell As Range
Dim sbuf As String
For Each cell In CellBlock
If Len(cell.text) > 0 Then sbuf = sbuf & cell.text & ","
Next
ConCatRange = Left(sbuf, Len(sbuf) - 1)
End Function

After concatenating the range using =ConCatRange(A1:A70)

copy/paste special>values.


Gord Dibben MS Excel MVP

On Tue, 19 Jun 2007 15:03:41 -0700, AZ ChrisD <AZ
 

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