PC Review


Reply
Thread Tools Rate Thread

CountIf for unfiltered cells.

 
 
=?Utf-8?B?d29vZGludmlsbGUgZGF2ZQ==?=
Guest
Posts: n/a
 
      4th Oct 2006
I'm trying to implement a countif for visible cells. When I use the filter it
doesn't seem to affect the values I get back for xlCellTypeVisible. This is
my function, I'm sure I am doing something stupid.


Function CountIfVisible(UserRange, criteria)
Dim count As Integer
count = 0
For Each cell In UserRange.SpecialCells(xlCellTypeVisible)
If cell.Value = criteria Then
count = count + 1
End If
Next cell
CountIfVisible = count
MsgBox count
End Function

Thanks for any help,
Dave


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      4th Oct 2006
If you're trying to use this UDF from a worksheet formula, then you're seeing
the trouble that excel has with .specialcells.

I think you're going to have to loop through the range and test to see if it's
visible.

===
BTW, if you're hiding rows via data|filter|autofilter, you could use the
worksheet formula:

=subtotal(3,a1:a10)

If you're using xl2003, then you could even use:
=subtotal(103,a1:a10)

=subtotal() was enhanced in xl2003 to ignore manually hidden rows.



woodinville dave wrote:
>
> I'm trying to implement a countif for visible cells. When I use the filter it
> doesn't seem to affect the values I get back for xlCellTypeVisible. This is
> my function, I'm sure I am doing something stupid.
>
> Function CountIfVisible(UserRange, criteria)
> Dim count As Integer
> count = 0
> For Each cell In UserRange.SpecialCells(xlCellTypeVisible)
> If cell.Value = criteria Then
> count = count + 1
> End If
> Next cell
> CountIfVisible = count
> MsgBox count
> End Function
>
> Thanks for any help,
> Dave


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?d29vZGludmlsbGUgZGF2ZQ==?=
Guest
Posts: n/a
 
      4th Oct 2006
Yeah subtotal works for count but not countif. I wish I could just pass in a
function to subtotal to do countif.

Is there a way to test the individual cell to see if it is visible?
--
- Dave


"Dave Peterson" wrote:

> If you're trying to use this UDF from a worksheet formula, then you're seeing
> the trouble that excel has with .specialcells.
>
> I think you're going to have to loop through the range and test to see if it's
> visible.
>
> ===
> BTW, if you're hiding rows via data|filter|autofilter, you could use the
> worksheet formula:
>
> =subtotal(3,a1:a10)
>
> If you're using xl2003, then you could even use:
> =subtotal(103,a1:a10)
>
> =subtotal() was enhanced in xl2003 to ignore manually hidden rows.
>
>
>
> woodinville dave wrote:
> >
> > I'm trying to implement a countif for visible cells. When I use the filter it
> > doesn't seem to affect the values I get back for xlCellTypeVisible. This is
> > my function, I'm sure I am doing something stupid.
> >
> > Function CountIfVisible(UserRange, criteria)
> > Dim count As Integer
> > count = 0
> > For Each cell In UserRange.SpecialCells(xlCellTypeVisible)
> > If cell.Value = criteria Then
> > count = count + 1
> > End If
> > Next cell
> > CountIfVisible = count
> > MsgBox count
> > End Function
> >
> > Thanks for any help,
> > Dave

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      4th Oct 2006
for each cell in Range("A2:A100")
if cell.EntireRow.Hidden = True then


End if
Next
--
Regards,
Tom Ogilvy



"woodinville dave" <(E-Mail Removed)> wrote in
message news:B0D3875A-4213-4C4B-BA0C-(E-Mail Removed)...
> Yeah subtotal works for count but not countif. I wish I could just pass
> in a
> function to subtotal to do countif.
>
> Is there a way to test the individual cell to see if it is visible?
> --
> - Dave
>
>
> "Dave Peterson" wrote:
>
>> If you're trying to use this UDF from a worksheet formula, then you're
>> seeing
>> the trouble that excel has with .specialcells.
>>
>> I think you're going to have to loop through the range and test to see if
>> it's
>> visible.
>>
>> ===
>> BTW, if you're hiding rows via data|filter|autofilter, you could use the
>> worksheet formula:
>>
>> =subtotal(3,a1:a10)
>>
>> If you're using xl2003, then you could even use:
>> =subtotal(103,a1:a10)
>>
>> =subtotal() was enhanced in xl2003 to ignore manually hidden rows.
>>
>>
>>
>> woodinville dave wrote:
>> >
>> > I'm trying to implement a countif for visible cells. When I use the
>> > filter it
>> > doesn't seem to affect the values I get back for xlCellTypeVisible.
>> > This is
>> > my function, I'm sure I am doing something stupid.
>> >
>> > Function CountIfVisible(UserRange, criteria)
>> > Dim count As Integer
>> > count = 0
>> > For Each cell In UserRange.SpecialCells(xlCellTypeVisible)
>> > If cell.Value = criteria Then
>> > count = count + 1
>> > End If
>> > Next cell
>> > CountIfVisible = count
>> > MsgBox count
>> > End Function
>> >
>> > Thanks for any help,
>> > Dave

>>
>> --
>>
>> Dave Peterson
>>



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      4th Oct 2006
Tom answered your question, but you really aren't using the equivalent of
=countif(). You're just using =subtotal(3, ...). The 3 means that you want to
use CountA as your subtotal function.





woodinville dave wrote:
>
> Yeah subtotal works for count but not countif. I wish I could just pass in a
> function to subtotal to do countif.
>
> Is there a way to test the individual cell to see if it is visible?
> --
> - Dave
>
> "Dave Peterson" wrote:
>
> > If you're trying to use this UDF from a worksheet formula, then you're seeing
> > the trouble that excel has with .specialcells.
> >
> > I think you're going to have to loop through the range and test to see if it's
> > visible.
> >
> > ===
> > BTW, if you're hiding rows via data|filter|autofilter, you could use the
> > worksheet formula:
> >
> > =subtotal(3,a1:a10)
> >
> > If you're using xl2003, then you could even use:
> > =subtotal(103,a1:a10)
> >
> > =subtotal() was enhanced in xl2003 to ignore manually hidden rows.
> >
> >
> >
> > woodinville dave wrote:
> > >
> > > I'm trying to implement a countif for visible cells. When I use the filter it
> > > doesn't seem to affect the values I get back for xlCellTypeVisible. This is
> > > my function, I'm sure I am doing something stupid.
> > >
> > > Function CountIfVisible(UserRange, criteria)
> > > Dim count As Integer
> > > count = 0
> > > For Each cell In UserRange.SpecialCells(xlCellTypeVisible)
> > > If cell.Value = criteria Then
> > > count = count + 1
> > > End If
> > > Next cell
> > > CountIfVisible = count
> > > MsgBox count
> > > End Function
> > >
> > > Thanks for any help,
> > > Dave

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?d29vZGludmlsbGUgZGF2ZQ==?=
Guest
Posts: n/a
 
      4th Oct 2006
Thanks a bunch! that solved my problem. My final function is:
Function CountIfVisible(UserRange, criteria)
Dim count As Integer
count = 0
For Each cell In UserRange
If cell.EntireRow.Hidden = False Then
If cell.Value = criteria Then
count = count + 1
End If
End If
Next cell
CountIfVisible = count
End Function

--
- Dave


"Tom Ogilvy" wrote:

> for each cell in Range("A2:A100")
> if cell.EntireRow.Hidden = True then
>
>
> End if
> Next
> --
> Regards,
> Tom Ogilvy
>
>
>
> "woodinville dave" <(E-Mail Removed)> wrote in
> message news:B0D3875A-4213-4C4B-BA0C-(E-Mail Removed)...
> > Yeah subtotal works for count but not countif. I wish I could just pass
> > in a
> > function to subtotal to do countif.
> >
> > Is there a way to test the individual cell to see if it is visible?
> > --
> > - Dave
> >
> >
> > "Dave Peterson" wrote:
> >
> >> If you're trying to use this UDF from a worksheet formula, then you're
> >> seeing
> >> the trouble that excel has with .specialcells.
> >>
> >> I think you're going to have to loop through the range and test to see if
> >> it's
> >> visible.
> >>
> >> ===
> >> BTW, if you're hiding rows via data|filter|autofilter, you could use the
> >> worksheet formula:
> >>
> >> =subtotal(3,a1:a10)
> >>
> >> If you're using xl2003, then you could even use:
> >> =subtotal(103,a1:a10)
> >>
> >> =subtotal() was enhanced in xl2003 to ignore manually hidden rows.
> >>
> >>
> >>
> >> woodinville dave wrote:
> >> >
> >> > I'm trying to implement a countif for visible cells. When I use the
> >> > filter it
> >> > doesn't seem to affect the values I get back for xlCellTypeVisible.
> >> > This is
> >> > my function, I'm sure I am doing something stupid.
> >> >
> >> > Function CountIfVisible(UserRange, criteria)
> >> > Dim count As Integer
> >> > count = 0
> >> > For Each cell In UserRange.SpecialCells(xlCellTypeVisible)
> >> > If cell.Value = criteria Then
> >> > count = count + 1
> >> > End If
> >> > Next cell
> >> > CountIfVisible = count
> >> > MsgBox count
> >> > End Function
> >> >
> >> > Thanks for any help,
> >> > Dave
> >>
> >> --
> >>
> >> Dave Peterson
> >>

>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      4th Oct 2006
Ignore this reply.

Dave Peterson wrote:
>
> Tom answered your question, but you really aren't using the equivalent of
> =countif(). You're just using =subtotal(3, ...). The 3 means that you want to
> use CountA as your subtotal function.
>
> woodinville dave wrote:
> >
> > Yeah subtotal works for count but not countif. I wish I could just pass in a
> > function to subtotal to do countif.
> >
> > Is there a way to test the individual cell to see if it is visible?
> > --
> > - Dave
> >
> > "Dave Peterson" wrote:
> >
> > > If you're trying to use this UDF from a worksheet formula, then you're seeing
> > > the trouble that excel has with .specialcells.
> > >
> > > I think you're going to have to loop through the range and test to see if it's
> > > visible.
> > >
> > > ===
> > > BTW, if you're hiding rows via data|filter|autofilter, you could use the
> > > worksheet formula:
> > >
> > > =subtotal(3,a1:a10)
> > >
> > > If you're using xl2003, then you could even use:
> > > =subtotal(103,a1:a10)
> > >
> > > =subtotal() was enhanced in xl2003 to ignore manually hidden rows.
> > >
> > >
> > >
> > > woodinville dave wrote:
> > > >
> > > > I'm trying to implement a countif for visible cells. When I use the filter it
> > > > doesn't seem to affect the values I get back for xlCellTypeVisible. This is
> > > > my function, I'm sure I am doing something stupid.
> > > >
> > > > Function CountIfVisible(UserRange, criteria)
> > > > Dim count As Integer
> > > > count = 0
> > > > For Each cell In UserRange.SpecialCells(xlCellTypeVisible)
> > > > If cell.Value = criteria Then
> > > > count = count + 1
> > > > End If
> > > > Next cell
> > > > CountIfVisible = count
> > > > MsgBox count
> > > > End Function
> > > >
> > > > Thanks for any help,
> > > > Dave
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson


--

Dave Peterson
 
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
need to show unfiltered data on chart pat67 Microsoft Access Queries 5 20th May 2011 02:03 PM
Open Form unfiltered DiHo Microsoft Access Form Coding 2 21st Aug 2008 05:13 PM
How do I delete only the unfiltered row? Leo Microsoft Excel Misc 1 2nd Jul 2008 03:58 AM
how to unfiltered by default Syphonics via AccessMonster.com Microsoft Access Forms 1 12th Feb 2008 01:38 PM
Countif if some cells contains ... Pedro Microsoft Excel Worksheet Functions 3 4th Sep 2003 12:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:03 PM.