How to I put a comma in between each column item from this code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This code combines all the data into one string. How can I parse it with a
comma in between each column entry.

Also would there be a way to add comments to each column right before the
comma?? Thanks

Set x = CreateObject("Word.Application")
x.Documents.Add
x.Visible = True

For Each cl In Selection

n = n & CStr(cl.Value)

Next

x.Selection.TypeText CStr(n)
 
This code combines all the data into one string. How can I parse it with a
comma in between each column entry.

Also would there be a way to add comments to each column right before the
comma?? Thanks

Set x = CreateObject("Word.Application")
x.Documents.Add
x.Visible = True

For Each cl In Selection

n = n & CStr(cl.Value)

Next

x.Selection.TypeText CStr(n)

Here's one way:

=======================
Sub foo()
Dim temp()
Dim n As String
Dim c As Range
Dim i As Long

ReDim temp(Selection.Count - 1)
For Each c In Selection
temp(i) = CStr(c.Value)
i = i + 1
Next c

n = Join(temp, ",")

Debug.Print n
End Sub
=========================


--ron
 

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

Back
Top