I have a large file with ~800K rows and I'm trying to generate an array from Column C from the names in Column B or ID in Column A (grouping Column A or B into 1 row and creating an array from Column C in the same row).
Please see attached sample data and output as I'm having a hard time explaining.
According to your attachment try this demonstration !
PHP Code:
Sub Demo1() Dim V, R&, L& With Worksheets("data").UsedRange.Rows ReDim V(1 To .Count - 1, 1 To 3) For R = 2 To .Count If .Cells(R, 1).Value = .Cells(R - 1, 1).Value Then V(L, 3) = V(L, 3) & "," & .Cells(R, 3).Value Else If L Then V(L, 3) = V(L, 3) & "}" L = L + 1 V(L, 1) = .Cells(R, 1).Value V(L, 2) = .Cells(R, 2).Value V(L, 3) = "{" & .Cells(R, 3).Value End If Next If L Then V(L, 3) = V(L, 3) & "}" End With Application.ScreenUpdating = False With Worksheets("output") .UsedRange.Offset(1).Clear .[A2:C2].Resize(L).Value = V End With Application.ScreenUpdating = True End Sub
Do you like it ? So thanks to click on bottom left star icon « ★ Add Reputation » !
Last edited by Marc L; 05-23-2017 at 10:49 PM.
Reason: optimization …
I should have thought this through much better as I have changed the scope of this.
I would like the curly brackets into quotes.
And I also need an equal number of comma separators even of there is no data present. The delimiter will need to be there even if it's blank. And no spaces before or after the comma delimiter.
I will import this into SQL via csv and the script reads all fields equally so if the max is 4 data points and one of the rows only has 2 data points, I will need 4 comma delimiters anyway.
Hi jindon I hate to keep doing this to you but I found another issue I didn't notice before. I can do this with a new request if it's too difficult revising your perfectly working script.
I have duplicate data in Column C and I need to remove it and keep only 1 instance.
So it would work exactly as you've written it but it would take into consideration duplicates within the group.
Please see attached for example of the duplication. It is based on Column A or Column B grouping and you'd remove Column C duplicates (keeping only 1 instance) within the group.
I'm not sure what I am doing wrong but excel keeps crashing now with the new script.
I'll PM you with the file I am working with (I don't want it to be pubic). If you have a minute, please run the script on the file so you can see what I mean.
Thank you very very much I truly appreciate your time.
Bookmarks