Article ID: 178435
Article Last Modified on 6/17/2005
Function MyFunction(CellRange As Object) As String
On Error GoTo ErrorHandler 'new line
If CellRange.Interior.Pattern = xlNone Then
MyFunction = "yes"
Else
MyFunction = "no"
End If
Exit Function 'new line
ErrorHandler: 'new line
MyFunction = "error" 'new line
End Function
In this user-defined function, the line "On Error GoTo ErrorHandler" causes
the function to continue if an error occurs. In this case, the error-
handling code causes the function to return a value of "error", instead of
"yes" or "no" or #VALUE!. After the formulas return "error", press
COMMAND+SHIFT+F9 to recalculate the worksheet.
Function MyFunction(CellRange As Object) As String
' This line will fail when you delete a row from the worksheet.
If CellRange.Interior.Pattern = xlNone Then
MyFunction = "yes"
Else
MyFunction = "no"
End If
End Function
Sub TestDelete()
Rows(2).Delete ' Deleting a row forces recalculation.
MsgBox "Delete succeeded."
End Sub
=MyFunction(C10)
and press CTRL+RETURN.
Additional query words: XL98
Keywords: kbprb KB178435