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.

[TABLE="width: 300, align: center"]
<tbody>[TR]
[TD]11723[/TD]
[TD]scott smith[/TD]
[TD]scott smith[/TD]
[/TR]
[TR]
[TD]11723[/TD]
[TD]jack harry[/TD]
[TD]scott smith, jack harry[/TD]
[/TR]
[TR]
[TD]11723[/TD]
[TD]ben phillips[/TD]
[TD]scott smith, jack harry, ben phillips[/TD]
[/TR]
[TR]
[TD]11122[/TD]
[TD]carrie cloud[/TD]
[TD]carrie cloud[/TD]
[/TR]
[TR]
[TD]11122[/TD]
[TD]gemma hugh[/TD]
[TD]carrie cloud, gemma hugh[/TD]
[/TR]
[TR]
[TD]11122[/TD]
[TD]billy temps[/TD]
[TD]carrie cloud, gemma hugh, billy temp[/TD]
[/TR]
[TR]
[TD]11122[/TD]
[TD]harry gent[/TD]
[TD]carrie cloud, gemma hugh, billy temp, harry gent[/TD]
[/TR]
</tbody>[/TABLE]


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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,224,816
Messages
6,181,143
Members
453,021
Latest member
Justyna P

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