Counting Multiple Items in Excel Based on Specific

2019-05-31 00:45发布

问题:

I looked through other questions and couldn't find what I needed.

Best if I explain as followed:

I have a spreadsheet that has three columns in it:

Product Name Vendor

Some vendors have the same product.

I need to count how many Product Names are identical by vendor.

All help is most appreciated.

Thank you,

user1114330

回答1:

Paste this formula in Cell C1

 =SUMPRODUCT(($A$1:$A$10=A1)*($B$1:$B$10=B1))

SNAPSHOT

However if you still want VBA, see this

Option Explicit

Sub Sample()
    Dim ws As Worksheet
    Dim lrow As Long

    Set ws = Sheets("Sheet1")

    With ws
        lrow = .Range("A" & .Rows.Count).End(xlUp).Row
        .Range("C1:C" & lrow).Formula = "=SUMPRODUCT(($A$1:$A$" & lrow & _
                                        "=A1)*($B$1:$B$" & lrow & "=B1))"
    End With
End Sub