ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   concatenate (https://www.excelbanter.com/excel-programming/359170-concatenate.html)

gwtreece

concatenate
 
I have the following

Col A Col Q Col Z
746 123
746 4789
746 124
748 8566
748 9586
748 852

I have this for about 3100 lines of data. I need to if Col A is the same
the return col B concatenate. So for Trailer # 746 return 123, 4789, 124 in
col Z. I did this about 2 years ago and quite frankly I had some help and no
longer remember how the macro needs to be written.

Please help. Thanks, Wanda

Bob Phillips[_6_]

concatenate
 

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
tmp = Cells(1, "A").Value
sNums = Cells(1, "Q").Value
For i = 2 To iLastRow
If Cells(i, "A").Value = tmp Then
sNums = sNums & ", " & Cells(i, "Q").Value
Else
j = j + 1
Cells(j, "Z").Value = sNums
sNums = Cells(i, "Q").Value
tmp = Cells(i, "A").Value
End If
Next i
j = j + 1
Cells(j, "Z").Value = sNums


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"gwtreece" wrote in message
...
I have the following

Col A Col Q Col Z
746 123
746 4789
746 124
748 8566
748 9586
748 852

I have this for about 3100 lines of data. I need to if Col A is the same
the return col B concatenate. So for Trailer # 746 return 123, 4789, 124

in
col Z. I did this about 2 years ago and quite frankly I had some help and

no
longer remember how the macro needs to be written.

Please help. Thanks, Wanda




Ronco

concatenate
 
Bob, I just came across your code for concatenating. It works great. I've
needed this for about a hundred years--gives me the flexibility I couldn't
get any other way. Thanks!

"Bob Phillips" wrote:


iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
tmp = Cells(1, "A").Value
sNums = Cells(1, "Q").Value
For i = 2 To iLastRow
If Cells(i, "A").Value = tmp Then
sNums = sNums & ", " & Cells(i, "Q").Value
Else
j = j + 1
Cells(j, "Z").Value = sNums
sNums = Cells(i, "Q").Value
tmp = Cells(i, "A").Value
End If
Next i
j = j + 1
Cells(j, "Z").Value = sNums


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"gwtreece" wrote in message
...
I have the following

Col A Col Q Col Z
746 123
746 4789
746 124
748 8566
748 9586
748 852

I have this for about 3100 lines of data. I need to if Col A is the same
the return col B concatenate. So for Trailer # 746 return 123, 4789, 124

in
col Z. I did this about 2 years ago and quite frankly I had some help and

no
longer remember how the macro needs to be written.

Please help. Thanks, Wanda






All times are GMT +1. The time now is 08:25 PM.

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