View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
johli johli is offline
external usenet poster
 
Posts: 1
Default Autofilter/xlVisible problem when counting rows


Hi

Have some problems here that I hope someone smarter than me can
solve...

I'm trying to find the number of cells in an autofilter range matching
a specific criteria but I can't even get a correct count of all visible
cells.

Have tried the following code:

Function CountRows()
Dim rng As Range
Set rng = ActiveSheet.AutoFilter.Range

CountRows = rng.Columns(1).SpecialCells(xlVisible).Count - 1
End Function

This will always return all cells not just the visible ones...

If I run a Sub as a macro like:
Sub CountRows()
Dim rng As Range
Set rng = ActiveSheet.AutoFilter.Range

msgbox rng.Columns(1).SpecialCells(xlVisible).Count - 1
End Sub

It will return the correct count...

WHY??? Why doesn´t the function do the same when used in the
worksheet??

/Regards Johan


--
johli
------------------------------------------------------------------------
johli's Profile: http://www.excelforum.com/member.php...o&userid=27388
View this thread: http://www.excelforum.com/showthread...hreadid=470917