Concatentate A1:AZ1 separated by ~

  • Thread starter Thread starter shortstop
  • Start date Start date
S

shortstop

Excel 2003 is my operating platform.

I have data in a row of my spreadsheet. A1:Z1 for example. I'd like to
concatenate it in VBA Code separated by a tilde "~" and have VBA put the
result in cell A10.

The code snippet below would suffice, I assume. However, it seems terribly
inefficient.

Range("A10").Value = Range("A1") & "~" & Range("B1")
........................... & "~" & Range("AZ1")

Can somebody provide guidance to make my code efficient.
 
sub joiner()

Dim s as string
s=Range("a1").value
Dim i as integer
for i = 1 to 26
s = s & "~" & range("a1").offset(0,i).value
next i

range("a10").value = s

end sub
 
That will get AA1 as well Sam.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
This is sloppy, but it does the job and is adaptable.

Sub testit()

Dim rngMyCells As Range

ActiveSheet.Range("A10").Value = ActiveSheet.Range("A1").Value
For Each rngMyCells In ActiveSheet.Range("B1", "Z1")
ActiveSheet.Range("A10").Value = _
ActiveSheet.Range("A10").Value & "~" & rngMyCells.Value
Next

End Sub
 
Range("A10").Value =
Join(Application.Transpose(Application.Transpose(Range("A1:Z1").Value)),
"~")
 

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