Sum the values in one column associated with the unique ID in another column. and concatenate the data

sontho

New Member
Joined
May 16, 2023
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I come from Vietnam . I am having over 100k data. But my data has duplicate phone numbers. But the data related to these duplicate phone numbers is different and inconsistent.

Thanks for everyone's help according to the desired result in excel

Thank you very much
1684248480246.png
 
OK. It could be a day or so before I can look at it.
wow , took 1 day or more. So I've bothered you too much. Thank you. Maybe instead of spawning it in batches, I'll just try pasting the formula every 50,000 lines at a time.

Once again sincerely thank you
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Give this a try with a copy of your workbook. It assumes the data is on the active sheet and that the results can be written to columns J:P of that same sheet.

VBA Code:
Sub sontho()
  Dim d As Object
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long, r As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  a = Range("a2", Range("G" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 7)
  For i = 1 To UBound(a)
    If d.exists(a(i, 1)) Then
      r = d(a(i, 1))
      b(r, 2) = b(r, 2) & " " & a(i, 2)
      If b(r, 3) = "" Then b(r, 3) = a(i, 3)
      b(r, 6) = b(r, 6) + a(i, 6)
      b(r, 7) = b(r, 7) + a(i, 7)
    Else
      k = k + 1
      d(a(i, 1)) = k
      For j = 1 To 7
        b(k, j) = a(i, j)
      Next j
    End If
  Next i
  With Range("J2:P2")
    .Resize(k).Value = b
    .Rows(0).Value = Range("A1:G1").Value
  End With
End Sub
 
Upvote 0
Give this a try with a copy of your workbook. It assumes the data is on the active sheet and that the results can be written to columns J:P of that same sheet.

VBA Code:
Sub sontho()
  Dim d As Object
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long, r As Long
 
  Set d = CreateObject("Scripting.Dictionary")
  a = Range("a2", Range("G" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 7)
  For i = 1 To UBound(a)
    If d.exists(a(i, 1)) Then
      r = d(a(i, 1))
      b(r, 2) = b(r, 2) & " " & a(i, 2)
      If b(r, 3) = "" Then b(r, 3) = a(i, 3)
      b(r, 6) = b(r, 6) + a(i, 6)
      b(r, 7) = b(r, 7) + a(i, 7)
    Else
      k = k + 1
      d(a(i, 1)) = k
      For j = 1 To 7
        b(k, j) = a(i, j)
      Next j
    End If
  Next i
  With Range("J2:P2")
    .Resize(k).Value = b
    .Rows(0).Value = Range("A1:G1").Value
  End With
End Sub
Thank you very much. I will try it
 
Upvote 0

Forum statistics

Threads
1,216,124
Messages
6,128,990
Members
449,480
Latest member
yesitisasport

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