I've found this code, and it almost does perfectly what I'm after. My only problem is, that this code sums more cells than I wanted.
My raw data has 7 columns (A-G). I need to check the duplicates based on multiple cells (A-H) and sums up G.
This code does the job but it also sums up every data in D,E,F,G (I only need a summary in G).
I've fairly new to VBA and tried to play with the numbers, but I've only managed to clear the values in D,E,F,G.
My raw data has 7 columns (A-G). I need to check the duplicates based on multiple cells (A-H) and sums up G.
This code does the job but it also sums up every data in D,E,F,G (I only need a summary in G).
I've fairly new to VBA and tried to play with the numbers, but I've only managed to clear the values in D,E,F,G.
Code:
Sub AB()
Dim a, i As Long, ii As Integer, b(), n As Long, z As String
With ActiveSheet.Range("a1").CurrentRegion
a = .Value
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
For i = 1 To UBound(a, 2): b(1, i) = a(1, i): Next
n = 1
With CreateObject("Scripting.Dictionary")
For i = 2 To UBound(a, 1)
z = a(i, 1) & ";" & a(i, 2) & ";" & a(i, 3) & ";" & a(i, 4) & ";" & a(i, 5) & ";" & a(i, 6)
If Not .exists(z) Then
n = n + 1: .Add z, n
For ii = 1 To 3: b(n, ii) = a(i, ii): Next
End If
For ii = 4 To UBound(a, 2)
b(.Item(z), ii) = b(.Item(z), ii) + a(i, ii)
Next
Next
End With
.Value = b
End With
End Sub