jmckeone
Well-known Member
- Joined
- Jun 3, 2006
- Messages
- 550
Ran across another post on the board concerning code to count non-hidden rows. However it would not work as a normal Sub but was written as a function. I am new to VBA and haven't a clue how to run a function nor what the benefit is of using a FUNCTION over a Sub. Can anyone help with this code as well as explain this question?
Code:
Function COUNTVISIBLE(Rng)
' Counts visible cells
Dim CellCount As Long
Dim cell As Range
Application.Volatile
CellCount = 0
Set Rng = Intersect(Rng.Parent.UsedRange, Rng)
For Each cell In Rng
If Not IsEmpty(cell) Then
If Not cell.EntireRow.Hidden And _
Not cell.EntireColumn.Hidden Then _
CellCount = CellCount + 1
End If
Next cell
COUNTVISIBLE = CellCount
End Function