ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB code to concatenate 100+ cells (https://www.excelbanter.com/excel-programming/352082-vbulletin-code-concatenate-100-cells.html)

LJones[_3_]

VB code to concatenate 100+ cells
 
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

Toppers

VB code to concatenate 100+ cells
 
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


"LJones" wrote:

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


Toppers

VB code to concatenate 100+ cells
 
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)


"Toppers" wrote:

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


"LJones" wrote:

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


LJones[_3_]

VB code to concatenate 100+ cells
 
Perfect! Thx again,
LJ

"Toppers" wrote:

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)


"Toppers" wrote:

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


"LJones" wrote:

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



All times are GMT +1. The time now is 02:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com