Summarize using VBA Scripting Dictionary

deba2020

New Member
Joined
Jan 8, 2020
Messages
26
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
I have a data which contains 18 columns, I need to summarize the data based on the 1st 2 columns and in the summary there will be just 3 columns as shown in below table
Raw Data in Sheet1

DEPOT / CUSTOMERSKUDESCRIPTIONBUSINESS LINEPRIMARY UOMSECONDARY UOMUNIT VOLUMEC1 (Y/N)SORQISOISO DATEDLVORDEREDSHIPPEDPENDINGPICKEDWEIGHT
Customer_1SKU1Product 1Business1EL5YES1498763764816354295409-Nov-2237627225110288200
Customer_2SKU2Product 2Business2EL1NO3575499337074806-Jun-223762722668451616800
Customer_3SKU1Product 3Business3EL2YES2055753500505330178505-Apr-22376272271500132018000
Customer_1SKU1Product 4Business4EL2YES2055753500507330178705-Apr-2237627228150014683200
Customer_5SKU5Product 5Business5EL2YES2055753566757336267830-May-223762722960035224800
Customer_3SKU1Product 6Business6EL10YES835863528928332785028-Apr-2237627230118211612100
Customer_1SKU1Product 7Business7EL4YES1909703534232333275402-May-22376272311521203200
Customer_2SKU1Product 8Business8EL18YES804583535595333406503-May-22376272329509311900
Customer_3SKU2Product 9Business9EL1NO3544187334195710-May-2237627233180017168400
Customer_1SKU2Product 10Business10EL16YES1316023516206331624218-Apr-2237627234100841600
Customer_2SKU2Product 11Business11EL10YES783723539301333743806-May-2237627235140013653500
Customer_2SKU2Product 12Business12EL1NO3545288334297611-May-223762723682862420400
Customer_13SKU2Product 13Business13EL10NO3545293334298011-May-223762723796722400
Customer_14SKU3Product 14Business14EL20NO3597923339112325-Jun-22376272382702502000
Customer_15SKU2Product 15Business15EL14NO3611702340392906-Jul-2237627239150717900



Need Summary in Sheet 2 as follows with these 3 columns (1st 2 columns and Sum of Column "Pending")

DEPOT / CUSTOMERSKUPENDING
Customer_1SKU1146
Customer_1SKU216
Customer_13SKU224
Customer_14SKU320
Customer_15SKU279
Customer_2SKU119
Customer_2SKU2407
Customer_3SKU1201
Customer_3SKU284
Customer_5SKU5248
 

Attachments

  • Summary.jpg
    Summary.jpg
    35.1 KB · Views: 5
  • Raw Data.jpg
    Raw Data.jpg
    196.4 KB · Views: 6
Hi, alternative..
VBA Code:
Sub test()
    Dim lst, i&, ky$, say&

    With Sheets("Sheet1")
        lst = .Range("A1:P" & .Cells(Rows.Count, 1).End(3).Row).Value
    End With

    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(lst)
            ky = lst(i, 1) & "|" & lst(i, 2)
            If Not .exists(ky) Then
                say = say + 1
                lst(say, 1) = lst(i, 1)
                lst(say, 2) = lst(i, 2)
                lst(say, 3) = lst(say, 16)
                .Item(ky) = say
            Else
                lst(.Item(ky), 3) = lst(.Item(ky), 3) + lst(say, 16)
            End If
        Next i
    End With

    With Sheets("Sheet2")
        .Cells.ClearContents
        .Range("A1").Resize(say, 3).Value = lst
    End With

End Sub
Excel Formula:
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,215,398
Messages
6,124,699
Members
449,180
Latest member
craigus51286

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