# Count Unique based on two criteria VBA

#### -=NO=-

##### New Member
Hello Dears

Please if anyone can support in that;

I need to convert the below formula to VBA code,

{=SUM(IF(("City"=Receiving[BRANCH])*('Build Dashboard'!I12=Receiving[CATEGORY LEVEL]), 1/COUNTIFS(Receiving[BRANCH],"City",Receiving[RECEIPT NUMBER],Receiving[RECEIPT NUMBER],Receiving[CATEGORY LEVEL],'Build Dashboard'!I12)), 0)}

The issue that I need a code to make a count for unique values depending on two different criteria, the count will be added in a table according to the input criteria

As per table below; the two criteria are (City & Category) and the unique count range is (Receipt no.).

 City Category Receipt no. X XX 222110130683 X XX 222110130683 Y YX 2310124850 Y XX 2110123413 X XX 2110123415 Y YX 2110123419

Then, the data developed will be copied in the below table
 City Category Count X XX ?? Y YX ??

#### alansidman

##### Well-known Member
I just make a simple example, If I have many columns in source sheet (not only these 3 columns), how can I edit in your code to fit my table.

Show a sample of data that is truly representative of your actual data.

### Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

#### -=NO=-

##### New Member
Replace with
VBA Code:
``  Cells(12, 12).Resize(.Count) = Application.Index(Application.Transpose(Application.Transpose(.Items)), 0, 3)``
Thanks Mr. Mohadin but it's stll not working

I made a sample sheet with the correct column numbers, If I may request from you to adjust the code after opening it.

#### alansidman

##### Well-known Member
Norton has blocked me from opening your file as it has deemed the site to be unsafe.

#### -=NO=-

##### New Member
Norton has blocked me from opening your file as it has deemed the site to be unsafe.

#### alansidman

##### Well-known Member
Latest when I try to open file

#### -=NO=-

##### New Member

Ple
Latest when I try to open file

View attachment 34797

#### -=NO=-

##### Well-known Member
Hi
Same RECEIPT NUMBER for x & y !!??
Sorry I'm confused

#### -=NO=-

##### New Member

I shall create a combobox contains all cities, once I select one like X, it shall get the number of transaction done with this city based on its category as (table in Target sheet) which will be "1"

Replies
19
Views
301
Replies
8
Views
176
Replies
5
Views
270
Replies
2
Views
169
Replies
0
Views
130

1,137,351
Messages
5,680,991
Members
419,948
Latest member
Sbakker1

### 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.

### Which adblocker are you using?

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

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