Check the number of visible lines in a listobject?
1 answer
The only way I could think of it was reliable for the columns to be hidden (simple enough for the columns to be grouped and arranged so that it needs to be handled) was using a loop:
'mode = 0 for Cells, >0 for Rows, <0 for Columns
Function getListObjectVisibleCount(lo As ListObject, Optional mode As Integer = 0) As Long
Dim visCnt As Long, area As Range
On Error Resume Next 'special cells raises an error if nothing is found
For Each area In lo.DataBodyRange.SpecialCells(xlCellTypeVisible).Areas
If mode = 0 Then
visCnt = visCnt + area.Columns.Count * area.Rows.Count
ElseIf mode > 0 Then
visCnt = visCnt + area.Rows.Count
Else
visCnt = visCnt + area.Columns.Count
End If
Next
On Error Goto 0
getListObjectVisibleCount = visCnt
End Sub
Edit: changed from Sub demo to function. Returns the number of cells, the number of rows, or the number of columns.
+5
source to share