Hi All,
I'm trying to remove duplicates and sum values. I have table which is looks like that.
please see code what i use below, it doesn't work properly, I have already blow my mind how to solve it.
I'm trying to remove duplicates and sum values. I have table which is looks like that.
item number | client | Date | Quantity |
167 | C10000038 | 28/01/2022 00:00 | 3 |
600831 | C10008630 | 27/01/2022 00:00 | 1 |
600831 | C10008630 | 27/01/2022 00:00 | 48 |
600827 | C10008630 | 28/01/2022 00:00 | 1 |
950114 | C10008630 | 28/01/2022 00:00 | 3 |
1357 | C10008630 | 28/01/2022 00:00 | 2 |
600827 | C10008630 | 28/01/2022 00:00 | 1 |
950115 | C10008630 | 27/01/2022 00:00 | 1 |
600831 | C10008630 | 27/01/2022 00:00 | 1 |
please see code what i use below, it doesn't work properly, I have already blow my mind how to solve it.
VBA Code:
Sub CombineDupes()
Dim x As Long
Dim r As Long
Dim arr() As Variant
Dim dic As Object
Const DELIM As String = "|"
Set dic = CreateObject("Scripting.Dictionary")
x = Cells(Rows.Count, 1).End(xlUp).Row
arr = Cells(1, 1).Resize(x, 4).Value
For x = LBound(arr, 1) + 1 To UBound(arr, 1)
If dic.exists(arr(x, 1)) Then
arr(x, 4) = arr(x, 4) + CDbl(Split(dic(arr(x, 1)), DELIM)(2))
Else
dic(arr(x, 1)) = arr(x, 2) & DELIM & arr(x, 3) & DELIM & arr(x, 4)
End If
dic(arr(x, 1)) = arr(x, 2) & DELIM & arr(x, 3) & DELIM & arr(x, 4)
Next x
r = UBound(arr, 1) + 2
Application.ScreenUpdating = False
Cells(r, 1).Resize(, 4).Value = Cells(1, 1).Resize(, 4).Value
r = r + 1
For x = 0 To dic.Count - 1
Cells(r + x, 1).Value = dic.keys()(x)
Cells(r + x, 2).Resize(, 3).Value = Split(dic.items()(x), DELIM)
Cells(r + x, 4).Value = CDbl(Cells(r, 4).Value)
Next x
Application.ScreenUpdating = True
Erase arr
Set dic = Nothing
End Sub