PDA

Click to See Complete Forum and Search --> : HOW TO: Excel: Detect a return of "Nothing" from a function ???


Webtest
Apr 6th, 2005, 03:04 PM
Esteemed Forum Participants and Lurkers:
===============================

EXCEL VBA

I have a function that returns a calculated range from a sheet or "Nothing" if the sheet is blank.

How can I detect that "Nothing" in my code? One of the Help Heap screens in my old Excel '97 says "you can detect Nothing with the IsNothing function", but of course, the IsNothing function doesn't exist, and that comment is omitted in the new XP version of Excel. I have been beating my head against a brick wall for a couple of hours now trying to find a simple solution to this.

Thank you for any comments, suggestions, and assistance in this inquiry.

RobDog888
Apr 6th, 2005, 03:09 PM
Is your function results being set to an object? If so you could do like so.
Set oRange = MyFunction
If TypeName(oRange) <> "Nothing" Then
MsgBox "Yea"
Else
MsgBox "Arg!"
End If

Webtest
Apr 6th, 2005, 03:20 PM
Thanks RobDog ...

Yes, my function returns a Range Object. It never fails ... right after I send a post to the Forum, I get a flash of brilliance and find an answer ...If myReturnedRange Is Nothing Then
MsgBox("Oh, it was nothing")
Else
MsgBox(myReturnedRange.address)
End If... also works.

Thanks for your help.