Option Explicit
Function CoolRange(MyRange As Range, Optional NoNumbers As Boolean, Optional NoTexts As Boolean) As Range
Dim RgConstants As Range, RgFormulas As Range
Dim MyOption As Integer
If NoNumbers = False Then MyOption = 1
If NoTexts = False Then MyOption = MyOption + 2
MyOption = MyOption + 20
On Error Resume Next
Set RgConstants = MyRange.SpecialCells(xlCellTypeConstants, MyOption)
Set RgFormulas = MyRange.SpecialCells(xlCellTypeFormulas, MyOption)
On Error GoTo 0
Select Case True
Case RgConstants Is Nothing And RgFormulas Is Nothing: Exit Function
Case RgConstants Is Nothing: Set CoolRange = RgFormulas
Case RgFormulas Is Nothing: Set CoolRange = RgConstants
Case Else: Set CoolRange = Union(RgConstants, RgFormulas)
End Select
Set RgConstants = Nothing
Set RgFormulas = Nothing
End Function
|