Check the number of visible lines in a listobject?

I know that I can check the number of lines in a list using:

loSättOmdömen.listRows.Count

      

But is there a way to check the number of visible lines of a list?

+3


source to share


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







All Articles