View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Determine if variable contains a valid range reference?

If the range is optional then you need to include Optional in the Function so
that it does not return an error. You then test for its value in the code.

Function ThisIsATest(MyRequiredRange As Range, _
Optional MyOptionalRange As Range)

If MyOptionalRange Is Nothing Then
'code for optional range not included
MsgBox "MyOptionalRange is Nothing"
Else
'code if included
MsgBox "MyOptionalRange is: " _
& MyOptionalRange.Address
End If


'Alternatively

If Not MyOptionalRange Is Nothing Then
'code here becaue it is included
MsgBox "MyOptionalRange is: " _
& MyOptionalRange.Address
Else
'code for optional range not included
MsgBox "MyOptionalRange is Nothing"
End If
--
Regards,

OssieMac