PC Review


Reply
Thread Tools Rate Thread

Count Unique Records in Filtered List

 
 
ryguy7272
Guest
Posts: n/a
 
      17th Nov 2008
I was trying to work with the below function, but it is too slow:
=SUMPRODUCT((C5:C15000<>"")/(COUNTIF(C5:C15000,C5:C15000&"")))

Subtotal(103,C5:C15000)
Works alright, but doesn't handle uniques...and it is slow too

Next, I tried this code, and it is certainly fast:
Sub Sub1() ' in sheet module
Dim sCell$, iErr&, iRowV&, iCount&
Dim CollPtr1 As Collection ' pointer to object
Set CollPtr1 = New Collection ' object
For iRowV = 5 To 15000
sCell = Cells(iRowV, 3).Value
If sCell <> "" Then ' ck blank
On Error Resume Next ' don't break
CollPtr1.Add "", sCell
iErr = Err.Number
On Error GoTo 0 ' restore error processing
If iErr = 0 Then iCount = iCount + 1
End If
Next iRowV
Cells(3, 3) = iCount
End Sub

However, it doesn't count unique records in a filtered list. I've seen a
Pivot Table count uniques, when the Pivot Table has a helper column.
http://www.contextures.com/xlPivot07.html#Unique

Is this the best way to go? Code, or a pivot table; In think functions will
be too slow (I need to do this for four columns). I'm looking for the best
solution, in terms of speed/performance.

Thanks,
Ryan---


--
RyGuy
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      17th Nov 2008
Perhaps in place of:
If sCell <> "" Then
we use:
If sCell <> "" And Cells(iRowV, 3).Rows.Hidden=False Then


This will force the code to ignore the items that the filter has hidden.
--
Gary''s Student - gsnu200814


"ryguy7272" wrote:

> I was trying to work with the below function, but it is too slow:
> =SUMPRODUCT((C5:C15000<>"")/(COUNTIF(C5:C15000,C5:C15000&"")))
>
> Subtotal(103,C5:C15000)
> Works alright, but doesn't handle uniques...and it is slow too
>
> Next, I tried this code, and it is certainly fast:
> Sub Sub1() ' in sheet module
> Dim sCell$, iErr&, iRowV&, iCount&
> Dim CollPtr1 As Collection ' pointer to object
> Set CollPtr1 = New Collection ' object
> For iRowV = 5 To 15000
> sCell = Cells(iRowV, 3).Value
> If sCell <> "" Then ' ck blank
> On Error Resume Next ' don't break
> CollPtr1.Add "", sCell
> iErr = Err.Number
> On Error GoTo 0 ' restore error processing
> If iErr = 0 Then iCount = iCount + 1
> End If
> Next iRowV
> Cells(3, 3) = iCount
> End Sub
>
> However, it doesn't count unique records in a filtered list. I've seen a
> Pivot Table count uniques, when the Pivot Table has a helper column.
> http://www.contextures.com/xlPivot07.html#Unique
>
> Is this the best way to go? Code, or a pivot table; In think functions will
> be too slow (I need to do this for four columns). I'm looking for the best
> solution, in terms of speed/performance.
>
> Thanks,
> Ryan---
>
>
> --
> RyGuy

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      17th Nov 2008
Unreal!! Perfect, too!!
Thanks GS!!!
Ryan---

--
RyGuy


"Gary''s Student" wrote:

> Perhaps in place of:
> If sCell <> "" Then
> we use:
> If sCell <> "" And Cells(iRowV, 3).Rows.Hidden=False Then
>
>
> This will force the code to ignore the items that the filter has hidden.
> --
> Gary''s Student - gsnu200814
>
>
> "ryguy7272" wrote:
>
> > I was trying to work with the below function, but it is too slow:
> > =SUMPRODUCT((C5:C15000<>"")/(COUNTIF(C5:C15000,C5:C15000&"")))
> >
> > Subtotal(103,C5:C15000)
> > Works alright, but doesn't handle uniques...and it is slow too
> >
> > Next, I tried this code, and it is certainly fast:
> > Sub Sub1() ' in sheet module
> > Dim sCell$, iErr&, iRowV&, iCount&
> > Dim CollPtr1 As Collection ' pointer to object
> > Set CollPtr1 = New Collection ' object
> > For iRowV = 5 To 15000
> > sCell = Cells(iRowV, 3).Value
> > If sCell <> "" Then ' ck blank
> > On Error Resume Next ' don't break
> > CollPtr1.Add "", sCell
> > iErr = Err.Number
> > On Error GoTo 0 ' restore error processing
> > If iErr = 0 Then iCount = iCount + 1
> > End If
> > Next iRowV
> > Cells(3, 3) = iCount
> > End Sub
> >
> > However, it doesn't count unique records in a filtered list. I've seen a
> > Pivot Table count uniques, when the Pivot Table has a helper column.
> > http://www.contextures.com/xlPivot07.html#Unique
> >
> > Is this the best way to go? Code, or a pivot table; In think functions will
> > be too slow (I need to do this for four columns). I'm looking for the best
> > solution, in terms of speed/performance.
> >
> > Thanks,
> > Ryan---
> >
> >
> > --
> > RyGuy

 
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
How to list and count unique records mikeg Microsoft Excel Discussion 4 6th May 2010 01:28 PM
How to Unfilter a List that has been filtered via Advanced Filter >Unique Records only Dave K Microsoft Excel Discussion 1 21st Jul 2008 05:51 PM
List & count unique records Sinner Microsoft Excel Programming 15 21st Mar 2008 08:19 PM
Count unique records in a list Leon Microsoft Excel Worksheet Functions 3 8th Oct 2004 05:45 PM
Count unique records in list =?Utf-8?B?YWg2NjY=?= Microsoft Excel Worksheet Functions 4 8th Oct 2004 04:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:36 PM.