PC Review


Reply
Thread Tools Rate Thread

Count a column "unique value only"

 
 
Galway
Guest
Posts: n/a
 
      28th Jul 2008
Is there a way to count the cell in a column, by unique value only.
I have a column with names of people.
There are only 10 names over 400 rows.
 
Reply With Quote
 
 
 
 
RadarEye
Guest
Posts: n/a
 
      28th Jul 2008
On 28 jul, 20:23, Galway <Terri...@gmail.com> wrote:
> Is there a way to count the cell in a column, by unique value only.
> I have a column with names of people.
> There are only 10 names over 400 rows.


Hi Galway,

If you know all the 10 names try:

=CountIf(Range(),"A Name")

eg:

A
1 Abe
2 Bert
3 Charlie
4 Dirk
5 Edward
6 Abe
7 Charlie

For B1: =COUNTIF(A1:A7,"Abe") the result will be 2


HTH
 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      28th Jul 2008
=SUMPRODUCT((A2:A200<>"")/COUNTIF(A2:A200,A2:A200&""))

--
__________________________________
HTH

Bob

"Galway" <(E-Mail Removed)> wrote in message
news:c1c07256-c801-4335-a139-(E-Mail Removed)...
> Is there a way to count the cell in a column, by unique value only.
> I have a column with names of people.
> There are only 10 names over 400 rows.



 
Reply With Quote
 
Galway
Guest
Posts: n/a
 
      28th Jul 2008
On Jul 28, 11:40*am, RadarEye <wouter.ma...@sogeti.nl> wrote:
> On 28 jul, 20:23, Galway <Terri...@gmail.com> wrote:
>
> > Is there a way to count the cell in a column, by unique value only.
> > I have a column with names of people.
> > There are only 10 names over 400 rows.

>
> Hi Galway,
>
> If you know all the 10 names try:
>
> =CountIf(Range(),"A Name")
>
> eg:
>
> * * A
> 1 *Abe
> 2 *Bert
> 3 *Charlie
> 4 *Dirk
> 5 *Edward
> 6 *Abe
> 7 *Charlie
>
> For B1: =COUNTIF(A1:A7,"Abe") the result will be 2
>
> HTH


Thank you so far..however
What if you do not know the names?
Galway
 
Reply With Quote
 
RadarEye
Guest
Posts: n/a
 
      29th Jul 2008
On 29 jul, 00:14, Galway <Terri...@gmail.com> wrote:
> On Jul 28, 11:40*am, RadarEye <wouter.ma...@sogeti.nl> wrote:
>
>
>
>
>
> > On 28 jul, 20:23, Galway <Terri...@gmail.com> wrote:

>
> > > Is there a way to count the cell in a column, by unique value only.
> > > I have a column with names of people.
> > > There are only 10 names over 400 rows.

>
> > Hi Galway,

>
> > If you know all the 10 names try:

>
> > =CountIf(Range(),"A Name")

>
> > eg:

>
> > * * A
> > 1 *Abe
> > 2 *Bert
> > 3 *Charlie
> > 4 *Dirk
> > 5 *Edward
> > 6 *Abe
> > 7 *Charlie

>
> > For B1: =COUNTIF(A1:A7,"Abe") the result will be 2

>
> > HTH

>
> Thank you so far..however
> What if you do not know the names?
> Galway- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -


Hi Galway,

If you do not know the names, and you dont want to mesh up your sheet
try this macro:

'-----------------Start
Public Sub CountUniqueValues()
ReDim strNames(0) As String
ReDim intCount(0) As Long
Dim lngLastRow As Long
Dim lngUniqueNames As Long
Dim rngSingle As Range
Dim intLastUnique As Integer
Dim intLoopUnique As Integer
Dim blnNotFound As Boolean
Dim strMessage As String

intLastUnique = -1
lngLastRow = Cells(1, 1).End(xlDown).Row
For Each rngSingle In Range(Cells(1, 1), Cells(lngLastRow,
1)).Cells
blnNotFound = True
If intLastUnique = -1 Then
strNames(0) = rngSingle.Value
intCount(0) = 1
intLastUnique = 0
Else
For intLoopUnique = 0 To intLastUnique
If strNames(intLoopUnique) = rngSingle.Value Then
intCount(intLoopUnique) = intCount(intLoopUnique)
+ 1
blnNotFound = False
Exit For
End If
Next
If blnNotFound Then
intLastUnique = intLastUnique + 1
ReDim Preserve strNames(intLastUnique) As String
ReDim Preserve intCount(intLastUnique) As Long
strNames(intLastUnique) = rngSingle.Value
intCount(intLastUnique) = 1
End If
End If
Next

strMessage = "Names" & vbTab & "Number" & vbNewLine
For intLoopUnique = 0 To intLastUnique
strMessage = strMessage & strNames(intLoopUnique) & _
vbTab & intCount(intLoopUnique) &
vbNewLine
Next
MsgBox strMessage
End Sub
'------------END
 
Reply With Quote
 
Galway
Guest
Posts: n/a
 
      5th Aug 2008
On Jul 29, 12:28*pm, RadarEye <wouter.ma...@sogeti.nl> wrote:
> On 29 jul, 00:14,Galway<Terri...@gmail.com> wrote:
>
>
>
>
>
> > On Jul 28, 11:40*am, RadarEye <wouter.ma...@sogeti.nl> wrote:

>
> > > On 28 jul, 20:23,Galway<Terri...@gmail.com> wrote:

>
> > > > Is there a way to count the cell in a column, by unique value only.
> > > > I have a column with names of people.
> > > > There are only 10 names over 400 rows.

>
> > > HiGalway,

>
> > > If you know all the 10 names try:

>
> > > =CountIf(Range(),"A Name")

>
> > > eg:

>
> > > * * A
> > > 1 *Abe
> > > 2 *Bert
> > > 3 *Charlie
> > > 4 *Dirk
> > > 5 *Edward
> > > 6 *Abe
> > > 7 *Charlie

>
> > > For B1: =COUNTIF(A1:A7,"Abe") the result will be 2

>
> > > HTH

>
> > Thank you so far..however
> > What if you do not know the names?
> >Galway- Tekst uit oorspronkelijk bericht niet weergeven -

>
> > - Tekst uit oorspronkelijk bericht weergeven -

>
> HiGalway,
>
> If you do not know the names, and you dont want to mesh up your sheet
> try this macro:
>
> '-----------------Start
> Public Sub CountUniqueValues()
> * * ReDim strNames(0) As String
> * * ReDim intCount(0) As Long
> * * Dim lngLastRow * * *As Long
> * * Dim lngUniqueNames *As Long
> * * Dim rngSingle * * * As Range
> * * Dim intLastUnique * As Integer
> * * Dim intLoopUnique * As Integer
> * * Dim blnNotFound * * As Boolean
> * * Dim strMessage * * *As String
>
> * * intLastUnique = -1
> * * lngLastRow = Cells(1, 1).End(xlDown).Row
> * * For Each rngSingle In Range(Cells(1, 1), Cells(lngLastRow,
> 1)).Cells
> * * * * blnNotFound = True
> * * * * If intLastUnique = -1 Then
> * * * * * * strNames(0) = rngSingle.Value
> * * * * * * intCount(0) = 1
> * * * * * * intLastUnique = 0
> * * * * Else
> * * * * * * For intLoopUnique = 0 To intLastUnique
> * * * * * * * * If strNames(intLoopUnique) = rngSingle.Value Then
> * * * * * * * * * * intCount(intLoopUnique) = intCount(intLoopUnique)
> + 1
> * * * * * * * * * * blnNotFound = False
> * * * * * * * * * * Exit For
> * * * * * * * * End If
> * * * * * * Next
> * * * * * * If blnNotFound Then
> * * * * * * * * intLastUnique = intLastUnique + 1
> * * * * * * * * ReDim Preserve strNames(intLastUnique) AsString
> * * * * * * * * ReDim Preserve intCount(intLastUnique) AsLong
> * * * * * * * * strNames(intLastUnique) = rngSingle.Value
> * * * * * * * * intCount(intLastUnique) = 1
> * * * * * * End If
> * * * * End If
> * * Next
>
> * * strMessage = "Names" & vbTab & "Number" & vbNewLine
> * * For intLoopUnique = 0 To intLastUnique
> * * * * strMessage = strMessage & strNames(intLoopUnique) & _
> * * * * * * * * * * * * * * *vbTab & intCount(intLoopUnique) &
> vbNewLine
> * * Next
> * * MsgBox strMessage
> End Sub
> '------------END- Hide quoted text -
>
> - Show quoted text -


Thanks!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Pivot Table Data with Column "Sum" rather than "count" defa Johnny_99 Microsoft Excel Misc 2 2nd Jan 2010 03:25 PM
count number of times when column A <="10" and Column B<="10" also Shup0739 Microsoft Frontpage 1 9th Jul 2009 06:12 PM
Count letter"B" in one column based on unique value among duplicat Mero Microsoft Excel Worksheet Functions 8 21st May 2009 12:26 PM
Count letter"B" in one column based on unique value among duplicat Mero Microsoft Excel Worksheet Functions 0 18th May 2009 08:39 PM
how can I count if column A="active" and column E="Job" in a list? =?Utf-8?B?QnJhbmRvbmk=?= Microsoft Excel Worksheet Functions 0 13th Oct 2006 11:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:12 AM.