Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Combine Cells into a Single String with Commas

Status
Not open for further replies.

gall3on

Technical User
Mar 15, 2007
35
US
I have a column of number values in Excel that grows over time.

Example:
Web IDs
1243
34565
2334
2357

Because of some reporting restrictions with another software, I have to constantly copy each cell value to a reporting field, with each value separated by a comma.

Example:

Enter IDs to find:
1243,34565,2334,2357

I know I can use the fuction =TEXT(Cell1 & "," & Cell2 & "," etc) to create a string which combines those values together into a single different cell to show all the values.

Here's my problem. Is there a way to code in VBA where I can keep appending the =Text function to keep adding my Web IDs as I create more so I can have them in a comma separated single cell format?

I hope this wasn't too confusing.

 





Hi,
Code:
Function RangeString(rng as range)
  dim r as range
  for each r in rng
    RangeString = RangeString & r.value & ","
  next
  RangeString = left(RangeString, len(RangeString)-1)
end function
Paste in a MODULE.

Use this User Defined Function, as you would, any spreadsheet function.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top