Get Unique counting based on multiple criteria and loop for each buyer

-=NO=-

New Member
Joined
May 9, 2011
Messages
27
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello Guys

Please advise to use the below code to loop through the below table to get unique values (# of POs made by each buyer)

VBA Code:
Dim MyDict As Object, c As Variant, LR1 As Long, LR2 As Long, rng As Range
Dim i

Set MyDict = CreateObject("Scripting.Dictionary")
LR1 = Sheets("PO").Range("R65536").End(xlUp).Row

    On Error Resume Next
    For i = 4 To 15
        For Each c In Sheets("PO").Range("B3:B" & LR1)
            If c.Offset(0, -1) = Sheet19.cmbBranchB Then
                If c.Offset(0, 16) = Sheets("PO Analysis").Range("J" & i) Then
                    If Not MyDict.exists(c.Value) Then MyDict.Add c.Value, Nothing
                End If
            End If
        Next c
        
        Sheets("PO Analysis").Range("J" & i).Offset(0, 1) = MyDict.Count
    Next

table.PNG
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I have a few suggestions that might get you more help in the forum ..
  1. Provide some meaningful sample data and the expected results (preferably with XL2BB ). You asked us to loop through the table to get unique values. All the values are unique and there is nothing that resembles a "buyer"

  2. Don't 'bump' too early or too often. #12 of the Forum Rules explains why and there is also information in the Guidelines (6 & 7)

  3. Update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Thanks Peter

The below is the source sheet, I need a code to count the unique POs in column B based on the below selected criteria:
1. cmbBranch (combo box for Branch)
2. cmbBuyer (combo box for buyer name)

Book1
ABCDEFGHIJKLMNOPQR
1BRANCHPO NUMBERORDER DATEITEM CODEITEM DESCRIPTIONUOMCATEGORYQTY. ORDEREDUNIT PRICEORDER VALUEQTY. RECEIVEDFOC QTY.GRN TOTAL VALUEQTY. PENDINGSUPPLIER CODESUPPLIER NAMECURRENCYBUYER
2City 1140096535Each12,500.002,500.0010$Buyer 1
3City 1140096534Each10420.004,200.00100$Buyer 2
4City 3140096531Each23450.0010,350.00230$Buyer 3
5City 4140096477Each20021.004,200.002000$Buyer 4
6City 5140096436Each3080.002,400.00300$Buyer 5
7City 6140096434Each4040.001,600.00040$Buyer 6
8City 2140096433Each13,200.003,200.0001$Buyer 7
9City 4140096353Each1250,605.13250,605.1310$Buyer 8
10City 4140096300Each23,000.006,000.0002$Buyer 9
11City 2140096298Each406.45258.00400$Buyer 2
12City 5140096298Each406.45258.00400$Buyer 1
13City 3140096293Each61,050.006,300.0006$Buyer 6
14City 3140096293Each6162.00972.0006$Buyer 8
Sheet1


After counting, copy data in the below sheet

KPI-Jeddah v4.xlsm
IJKLM
1
2Per Employee
3Buyer# of POsTotal Value / $%
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
PO Analysis
Cell Formulas
RangeFormula
L4:L15L4=IF(J4="","",SUMIFS(PO_21[ORDER VALUE],PO_21[BUYER],J4))
M4:M15M4=IFERROR(L4/$L$17,"")
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,785
Members
449,095
Latest member
m_smith_solihull

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