A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"COUNTU" function in Excel to count unique entries in a range



 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old June 4th, 2005, 08:53 PM
Alan Beban
external usenet poster
 
Posts: n/a
Default

The following is a UDF that provides for the seven cases set forth by
Harlan Grove below; watch for word wrap:.

Function COUNTU(InputRange, Criterion)
Rng = InputRange.Address
Select Case Criterion
Case "NonBlankText"
COUNTU =
Evaluate("=SUMPRODUCT(ISTEXT(Rng)*ISNUMBER(1/(Rng""""))/COUNTIF(Rng,Rng&""""))")
Case "PositiveNumbers"
COUNTU =
Evaluate("=SUMPRODUCT(ISNUMBER(Rng)*ISNUMBER(1/(Rng0))/COUNTIF(Rng,Rng&""""))")
Case "NumbersOrText"
COUNTU =
Evaluate("=SUMPRODUCT((ISNUMBER(Rng)+ISTEXT(Rng))/COUNTIF(Rng,Rng&""""))")
Case Else
COUNTU = Evaluate("=SumProduct(" & Criterion & "(" & Rng &
") /" & _
"CountIf(" & Rng & ", " & Rng & "&""""))")
End Select
End Function

The parameters for Criterion are, respectively:

"ISNUMBER"
"ISTEXT"
"NonBlankText"
"ISERROR"
"ISLOGICAL"
"PositiveNumbers"
"NumbersOrText"

As mentioned in an earlier post, the results for "ISTEXT" and
"NumbersOrText" work only if the range does not include blank cells (as
contrasted with cells containing the empty string--i.e.,"")

Alan Beban

Harlan Grove wrote:
Alan Beban wrote...

Harlan Grove wrote:

. . .

Fine. =ROWS(ArrayUniques(A1:A15)) returns the distinct count excluding
blanks, and =ROWS(ArrayUniques(A1:A15,,,FALSE)) returns the distinct
count including blanks.

To count only distinct numbers in Rng,

=SUMPRODUCT(ISNUMBER(Rng)/COUNTIF(Rng,Rng&""))


To count only distinct text including "" in Rng,

=SUMPRODUCT(ISTEXT(Rng)/COUNTIF(Rng,Rng&""))


To count only distinct text excluding "" in Rng,

=SUMPRODUCT(ISTEXT(Rng)*ISNUMBER(1/(Rng""))/COUNTIF(Rng,Rng&""))


To count distinct error values in Rng,

=SUMPRODUCT(ISERROR(Rng)/COUNTIF(Rng,Rng&""))


To count distinct logical values in Rng,

=SUMPRODUCT(ISLOGICAL(Rng)/COUNTIF(Rng,Rng&""))


To count distinct positive numbers in range,

=SUMPRODUCT(ISNUMBER(Rng)*ISNUMBER(1/(Rng0))/COUNTIF(Rng,Rng&""))


To count distinct numbers or text in Rng,

=SUMPRODUCT((ISNUMBER(Rng)+ISTEXT(Rng))/COUNTIF(Rng,Rng&""))

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion SVC Worksheet Functions 9 February 28th, 2005 02:29 PM
Return a count of unique entries? Tony Running & Setting Up Queries 2 February 3rd, 2005 04:50 PM
Pivot Table Access 2000? Air-ron General Discussion 2 October 29th, 2004 06:19 PM


All times are GMT +1. The time now is 07:43 AM.


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