Unique Cells in Column

mikechambers

Active Member
Joined
Apr 27, 2006
Messages
397
Something I can't understand. If Excel can quickly count the number of unique cells in a column of data when you apply a filter, then why isn't there a function to return that number? Seems like a given, right? Is there a way to "tap into" the filter somehow with VBA or a custom function?

I just have a list of dates in a column, and I need to figure out how many different days are included in it so I can get an average.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If your dates are in range A1:A20
In range B1 enter this formula:
Code:
=COUNTIF($A$1:$A$20,A1)
Drag this formula down to B20. Then in C1 enter:
Code:
=COUNTIF($B$1:$B$20,1)
Your value in C1 will tell you the number of unique values.

Not sure if this is quickest/ideal way but works for m
 
Upvote 0
Assuming your dates are in A2:A11, try:

Code:
=SUM(IF(FREQUENCY(IF(A2:A11<>"",MATCH(A2:A11,A2:A11,0)),ROW(A2:A11)-ROW(A2)+1),1))
Which requires array entering, i.e. with CTRL+SHIFT+ENTER.

Matty
 
Upvote 0
Alan Patridge:
"I know lying is wrong, but if the elephant man came in now in a blouse with some make up on, and said "How do I look?" Would you say, bearing in mind he's depressed and has respiratory problems, would you say "Go and take that blusher off you mis-shapened elephant tranny!" No, you'd say "You look nice... John"

Amusing... :laugh:

Matty
 
Upvote 0
Something I can't understand. If Excel can quickly count the number of unique cells in a column of data when you apply a filter, then why isn't there a function to return that number? Seems like a given, right? Is there a way to "tap into" the filter somehow with VBA or a custom function?

I just have a list of dates in a column, and I need to figure out how many different days are included in it so I can get an average.
This array formula** will count the unique dates in the filtered (or unfiltered) range A3:A20.

=SUM(IF(FREQUENCY(IF(SUBTOTAL(2,OFFSET(A3,ROW(A3:A20)-ROW(A3),)),A3:A20),A3:A20),1))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.
 
Upvote 0
This array formula** will count the unique dates in the filtered (or unfiltered) range A3:A20.

=SUM(IF(FREQUENCY(IF(SUBTOTAL(2,OFFSET(A3,ROW(A3:A20)-ROW(A3),)),A3:A20),A3:A20),1))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

I got the correct answer even without CSE. Thanks!
 
Upvote 0
Assuming your dates are in A2:A11, try:

Code:
=SUM(IF(FREQUENCY(IF(A2:A11<>"",MATCH(A2:A11,A2:A11,0)),ROW(A2:A11)-ROW(A2)+1),1))
Which requires array entering, i.e. with CTRL+SHIFT+ENTER.

Matty

This worked as well, but slower. Thanks!
 
Upvote 0
I got the correct answer even without CSE. Thanks!
If the data is unfiltered then it'll work without array entering but as soon as you apply the filter that'll cause an incorrect result if not array entered.

You're welcome. Thanks for the feedback! :cool:
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,547
Messages
6,179,436
Members
452,915
Latest member
hannnahheileen

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