How to Concat or VBA Based on a cell value

scottyyboyy

New Member
Joined
Feb 2, 2015
Messages
41
hi all,

i have 800,00 rows of data and i need to move the text into 1 cell where they have a matching value in another cell.

11723scott smithscott smith
11723jack harryscott smith, jack harry
11723ben phillipsscott smith, jack harry, ben phillips
11122carrie cloudcarrie cloud
11122gemma hughcarrie cloud, gemma hugh
11122billy tempscarrie cloud, gemma hugh, billy temp
11122harry gentcarrie cloud, gemma hugh, billy temp, harry gent

<tbody>
</tbody>


so if the number matches in column A then i need it to look like column c

i have tried using a normal concatenate but this doesn't work due to the amount or rows and data

Can anyone help with this and sorry if i'm not making sense
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
try this on a copy of your file.

Code:
Sub do_it()
Range("C:C").ClearContents
[C1] = [B1]

For r = 2 To Cells(Rows.Count, "A").End(xlUp).Row

If Cells(r, "A") = Cells(r - 1, "A") Then

Cells(r, "C") = Cells(r - 1, "C") & ", " & Cells(r, "B")


Else
Cells(r, "C") = Cells(r, "B")
End If
Next r
End Sub

hth,

Ross
 
Upvote 0
If your data starts on row 2, and is sorted by the value in A, put this formula in C2:


=IF(A2<>A1,B2,C1&", "&B2)

and drag down. If your data is not sorted, use this formula:

=IFERROR(LOOKUP(2,1/($A$1:$A1=A2),$C$1:$C1)&", ","")&B2


With 800,000 rows though, you might be better off running a macro as needed. Ross's is a good start, but we can speed it up by using internal arrays.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top