Thread: How many rows?
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default How many rows?

use the subtotal worksheet function

if application.Subtotal(3,Range("A2:A500"))


where Column A holds numbers. Look at help for Subtotal in Excel itself for
all options.

Subtotal only counts the visible cells in the filtered range.

Dim rng as Range
On Error Resume Next
set rng = Range("A2:A500").SpecialCells(xlVisible)
On Error goto 0
if not rng is nothing then
for each cell in rng

--
Regards,
Tom Ogilvy



"John" wrote:

People,
I have an Excel worksheet and I have applied an autofilter to a
particular column. The result is a filtered set of rows. Using VBA, what
is the easiest way to,
a) tell if any rows with data are in the filtered set (i.e. did the
filter find anything that met the criteria)?
b) get a count of how many rows with data, are shown in the filtered set?
c) loop through rows/columns/cells in the filtered set?

A bit of background. I write VBA for Project and in Project all one
needs to do to determine if a filter shows anything is to check for an
activeselection 0. Looping is very simple - just loop through all
tasks/resources in the activeselection.

John
Project MVP