Function to display a count of visible cells/rows... doesn't

G

Guest

This is what happens when you take a couple of months away from VBA...

I'm trying to write a function to display the number of visible wows with a
range of cells.

Function CountVisibleRows(TheRange)
Dim CellToCount As Range
Dim RunningTotal As Long
RunningTotal = 0
For Each CellToCount In TheRange
If CellToCount.Row.Hidden = False Then
RunningTotal = RunningTotal + 1
End If
Next CellToCount
CountVisibleRows = RunningTotal
End Function

but I'm getting a message to say that .row is an invalid qualifier.
It's late in the day 9well, it is for me, anyway) and my brain has entered
the twilight zone.

Can anyone please help?

Thanks in advance

Pete
 
C

Chip Pearson

Peter,

The Row property returns the row number of a range, not a
reference to a row. Change

If CellToCount.Row.Hidden = False Then
to
If CellToCount.EntireRow.Hidden = False Then


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



message
news:D[email protected]...
 
B

Bob Phillips

Function CountVisibleRows(TheRange)
Dim CellToCount As Range
Dim RunningTotal As Long
RunningTotal = 0
For Each CellToCount In TheRange.Rows
If Not CellToCount.EntireRow.Hidden Then
RunningTotal = RunningTotal + 1
End If
Next CellToCount
CountVisibleRows = RunningTotal
End Function


--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)
 
G

Guest

EntireRow!!!
It's scary how quickly these things drop oput of the grey matter.
Thanks a million, Chip - you're a lifesaver!

Pete
 
D

Dana DeLouis

...to display the number of visible rows with a
range of cells.

Maybe another option:

Function CountVisibleRows(TheRange)
Application.Volatile
Dim r As Range '(R)ow
For Each r In TheRange.EntireRow
CountVisibleRows = CountVisibleRows - Not (r.Hidden)
Next r
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top