I would suggest that HasValidation() returns either True or False, not maybe?...
Option Explicit
Public Function HasValidation(ByVal rng As Range) As Boolean
Dim itHas As Boolean, cell As Range, eID As Long, eSRC As String, eDESC As String
If Err.Number <> 0 Then
eID = Err.Number
eSRC = Err.Source
eDESC = Err.Description
Err.Clear
End If
On Error Resume Next
If Not rng Is Nothing Then
itHas = Not Intersect(rng.SpecialCells(xlCellTypeAllValidation), rng) Is Nothing
End If
If Err.Number <> 0 Or eID <> 0 Then
If eID = 0 Then Err.Clear Else Err.Raise eID, eSRC, eDESC
End If
HasValidation = itHas
End Function
Or GetValidationRange() that returns a Range or Nothing
Public Function GetValidationRange(ByVal rng As Range) As Range
Dim vRng As Range, cell As Range, eID As Long, eSRC As String, eDESC As String
If Err.Number <> 0 Then
eID = Err.Number
eSRC = Err.Source
eDESC = Err.Description
Err.Clear
End If
On Error Resume Next
If Not rng Is Nothing Then
Set vRng = Intersect(rng.SpecialCells(xlCellTypeAllValidation), rng)
End If
If Err.Number <> 0 Or eID <> 0 Then
If eID = 0 Then Err.Clear Else Err.Raise eID, eSRC, eDESC
End If
Set GetValidationRange = vRng
End Function
.
In your code
- The parameter name (
cell) implies that it expects a single cell - The
Nullreturn type can cause issues (not very used in normal operations) - As a user of the function I don't really know what to do with the result
- Should I be looking some more for cells with validation or not?
Edit
@DanielMcCracken has a valid point about changing the error chain
- I updated the answer to preserve the previous error