SpecialCells(xlCellTypeVisible) not working in UDF

后端 未结 1 436
清酒与你
清酒与你 2020-12-11 18:15

Based on the question posed by @Chips Ahoy, I decided to create a UDF to find the PercentRank of visible cells in a range.

While @Chips seems happy with my syntax co

相关标签:
1条回答
  • It seems that SpecialCells is known to fail in UDFs. A few sources: 1, 2, 3

    You'd have to create your own function. Perhaps something like this:

    Function VisiblePercentRank(x As Range, RankVal As Double)
        Debug.Print x.Address, VisibleCells(x).Address
        VisiblePercentRank = WorksheetFunction.PercentRank(VisibleCells(x), RankVal)
    End Function
    
    Private Function VisibleCells(rng As Range) As Range
        Dim r As Range
        For Each r In rng
            If r.EntireRow.Hidden = False Then
                If VisibleCells Is Nothing Then
                    Set VisibleCells = r
                Else
                    Set VisibleCells = Union(VisibleCells, r)
                End If
            End If
        Next r
    End Function
    
    0 讨论(0)
提交回复
热议问题