Worksheet function & SpecialCells(xlCellTypeVisible)?
SpecialCells performs a type of selection and triggers the
Worksheet_SelectionChange event under certain circumstances. Guess it can't
be used with UDFs for that reason.
Here's one possible workaround:
Public Function VISIBLE(rngCur As Range) As Range
Dim rngRow As Range, rngCol As Range
Dim rngVisRow As Range, rngVisCol As Range
Dim cell As Range, rngVis As Range
Application.Volatile
For Each rngRow In rngCur.Rows
If rngRow.EntireRow.Hidden = False Then
If rngVisRow Is Nothing Then
Set rngVisRow = rngRow
Else
Set rngVisRow = _
Union(rngRow, rngVisRow)
End If
End If
Next rngRow
For Each rngCol In rngCur.Columns
If rngCol.EntireColumn.Hidden = False Then
If rngVisCol Is Nothing Then
Set rngVisCol = rngCol
Else
Set rngVisCol = _
Union(rngCol, rngVisCol)
End If
End If
Next rngCol
For Each cell In rngVisRow.Cells
If Not Application.Intersect( _
cell, rngVisCol) Is Nothing Then
If rngVis Is Nothing Then
Set rngVis = cell
Else
Set rngVis = Union(cell, rngVis)
End If
End If
Next cell
If Not rngVis Is Nothing Then
Set VISIBLE = rngVis
Else
Set VISIBLE = Nothing
End If
End Function
"Charley Kyd" wrote in message
...
This function works as expected when I call it from a subroutine. But when
I
call it as a worksheet function, it always returns rngCur no matter how
many
rows are hidden.
Public Function VISIBLE(rngCur As Range) As Range
Application.Volatile
Set VISIBLE = rngCur.SpecialCells(xlCellTypeVisible)
End Function
SpecialCells isn't causing an action. Why isn't it working? Can anyone
suggest a workaround?
Thanks.
Charley
|