Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Counting Unique Observations

Does anyone know how to program a function in VBA that will count the total
number of unique observations in an array?

I imagine that the syntax would be:

=UNIQUE(array)

For instance, if an array of 5 observation look like this

apple
orange
apple
apple
banana

the Unique() function would return 3.

I am aware that you can do this with a pivot table, but the unique function
would be a lot more convenient. It is also probable there is another way to
do this with built-in excel functions.

Please let me know if you have any ideas.

Thanks,
Henrik
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Counting Unique Observations

Hi
a worksheet formula
=SUMPRODUCT((array<"")/(COUNTIF(array,array)+(array="")))

--
Regards
Frank Kabel
Frankfurt, Germany
"Henrik" schrieb im Newsbeitrag
...
Does anyone know how to program a function in VBA that will count the
total
number of unique observations in an array?

I imagine that the syntax would be:

=UNIQUE(array)

For instance, if an array of 5 observation look like this

apple
orange
apple
apple
banana

the Unique() function would return 3.

I am aware that you can do this with a pivot table, but the unique
function
would be a lot more convenient. It is also probable there is another way
to
do this with built-in excel functions.

Please let me know if you have any ideas.

Thanks,
Henrik



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Counting Unique Observations

For information, here is a UDF

Function Unique(inArray As Range) As Long
Dim colItems As Collection
Dim cell As Range

Set colItems = New Collection
On Error Resume Next
For Each cell In inArray
colItems.Add cell.Value, CStr(cell.Value)
Next cell
Unique = colItems.Count

End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Frank Kabel" wrote in message
...
Hi
a worksheet formula
=SUMPRODUCT((array<"")/(COUNTIF(array,array)+(array="")))

--
Regards
Frank Kabel
Frankfurt, Germany
"Henrik" schrieb im Newsbeitrag
...
Does anyone know how to program a function in VBA that will count the
total
number of unique observations in an array?

I imagine that the syntax would be:

=UNIQUE(array)

For instance, if an array of 5 observation look like this

apple
orange
apple
apple
banana

the Unique() function would return 3.

I am aware that you can do this with a pivot table, but the unique
function
would be a lot more convenient. It is also probable there is another way
to
do this with built-in excel functions.

Please let me know if you have any ideas.

Thanks,
Henrik





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting number of observations within a date range? Nic Excel Worksheet Functions 7 April 20th 07 09:20 AM
How to find the top 5% observations Bin Excel Discussion (Misc queries) 4 June 26th 06 08:23 PM
Listing Unique Observations Henrik Excel Worksheet Functions 3 February 7th 05 11:16 PM
Number of Observations Diane Excel Discussion (Misc queries) 3 December 21st 04 09:10 PM
Formulas for...1. Counting unique cells 2. Display unique contents J Excel Programming 0 April 23rd 04 09:20 PM


All times are GMT +1. The time now is 07:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"