VBA to Summarise Amount based on Unique ID column

dids86

New Member
Joined
Aug 15, 2024
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'd like to be able to utilise a VBA whereby the data is summarised by amount based on a unique id column as per the below.

1742896709671.png


Thank you for your help

Tom
 

Attachments

  • 1742896639533.png
    1742896639533.png
    21.2 KB · Views: 2
Start by adding a new sheet named "Summary" and add the headers in row 1 to match the headers in your data sheet. Then with your data sheet being the active sheet, run this macro:
VBA Code:
Sub SummarizeData()
    Application.ScreenUpdating = False
    Dim v As Variant, i As Long, dic As Object, desWS As Worksheet, tot As Long
    Set desWS = Sheets("Summary")
    v = Range("A2", Range("A" & Rows.Count).End(xlUp)).Resize(, 7).Value
    Set dic = CreateObject("Scripting.Dictionary")
    For i = LBound(v) To UBound(v)
        If Not dic.exists(v(i, 6)) Then
            dic.Add v(i, 6), Nothing
            Range("A1").AutoFilter 6, v(i, 6)
            tot = WorksheetFunction.Sum(Range("G2", Range("G" & Rows.Count).End(xlUp)).SpecialCells(xlVisible))
            desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 7).Value = Array(v(i, 1), v(i, 2), v(i, 3), v(i, 4), v(i, 5), v(i, 6), tot)
        End If
    Next i
    Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

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