Alter Sum Amounts by matching two criteria

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
882
Hi to all of you, kindly requesting to provide me support for a VBA code so that to alter my below data. If the columns “A” and “C” match, should “SUM” the amounts for each month from Col. “D” to “P”. Therefore that the spreadsheet contains 5000+ rows. I present below an extract of my original data and the expected result. Thank you all in advance

Original data

1613461217902.png


Expected result

1613461235546.png
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi
Try
VBA Code:
Sub test()
    Dim a, b As Variant, i, ii
    a = Range("a5:a" & Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 16)
    ReDim b(1 To UBound(a, 2))
    With CreateObject("scripting.dictionary")
        For i = 2 To UBound(a)
            For ii = 1 To UBound(b): b(ii) = a(i, ii): Next
            If a(i, 1) <> 0 Then
                If Not .exists(a(i, 1)) Then
                    .Add a(i, 1), b
                Else
                    For ii = 4 To UBound(b): b(ii) = b(ii) + .Item(a(i, 1))(ii): Next
                    .Item(a(i, 1)) = b
                End If
            End If
        Next
        Sheets("sheet2").Cells(1, 1).Resize(, UBound(a, 2)) = a
        Sheets("sheet2").Cells(2, 1).Resize(.Count, UBound(a, 2)) = Application.Index(.items, 0, 0)
    End With
End Sub

PS: Result in sheet names sheet2
 
Last edited:
Upvote 0
Thank you Mohadin! it works perfect and it based on my data. Thank you for your time spent for my project. Hv a great, lovely day!
 
Upvote 0
Cannot manipulate data in pictures. Suggest you upload samples using XL2BB
I am sorry alan, i presented in picture because is more clear the columns and rows. My data was in a huge file and so i couldn't. However thank for your interesting to resolve my issue.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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