VB code to concatenate 100+ cells

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

Guest

Hello,

Very amateur VB user, need help!

I need to write VB code to concatenate the data in 100 or more cells into a
single string. This is easy for a small number of cells:

ActiveCell.Offset(0, 0).FormulaR1C1 = _
ActiveCell.Offset(0, -1) & "," & ActiveCell.Offset(0, -2) etc.

But how do I do this without needing to type the "ActiveCell.Offset" 100
times? Is there any way to included a for/next loop within the concatenation?

Thanks!
/LJ
 
Hi,


Dim myString as string

myString=""

For r=1 to 100
myString=MyString & cells(r,1) <=== Rows 1 to 100 of column A
next r
 
Soory ... forgot about comma:

Dim myString as string

myString=""

For r=1 to 100
myString=MyString & cells(r,1) & "," <=== Rows 1 to 100 of column A
next r

myString=left(myString,len(mystring)-1)
 
Perfect! Thx again,
LJ

Toppers said:
Soory ... forgot about comma:

Dim myString as string

myString=""

For r=1 to 100
myString=MyString & cells(r,1) & "," <=== Rows 1 to 100 of column A
next r

myString=left(myString,len(mystring)-1)
 

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

Similar Threads

Copy, paste append from cell above 1
Inserting 2 columns when cells don't match 6
fill range 4
Help with formula in vb coding 5
Looping code 3
Copy and paste 1
Workbook_Open vs Auto_Open 4
Select Case 13

Back
Top