On the left is the hypothetical database. On the right is the result I would like to obtain. I would like to print all of the items of type B, as well as the sum and the count. I'm stuck and I'm not able to go ahead. Could you please help me out? Thanks.
Private Sub CommandButton1_Click() Dim dicDistincts As Scripting.Dictionary, _ dicDuplicates As Scripting.Dictionary Set dicDistincts = New Scripting.Dictionary Set dicDuplicates = New Scripting.Dictionary Dim i As Integer For i = 2 To 10 If Cells(i, 1).Value = "B" Then If Not dicDistincts.Exists(Cells(i, 2).Value) Then dicDistincts.Add Key:=Cells(i, 2).Value, Item:=Cells(i, 2).Value Else dicDuplicates.Add Key:=Cells(i, 2).Value, Item:=Cells(i, 2).Value End If End If Next i For i = 0 To dicDuplicates.Count - 1 Cells(i + 1, 9).Value = WorksheetFunction.CountIfs(Range("a2:a10"), "B", Range("b2:b10"), dicDistincts.keys(i)) Next i End Sub EDIT: I tried with countifs but it return 0 for banana, apple and strawberry
EDIT 2: I corrected the countifs. Now it works.

COUNTIFSandSUMIFS?Application.WorksheetFunction.CountIfs? Or is this an assignment where you have to use a scripting dictionary?