LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
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


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The name ... either conflicts with a valid range reference or isinvalid for Excel. Greg Lovern Excel Programming 6 November 15th 13 07:10 PM
Conflict with Valid Range Reference Error in Microsoft Excel 2007 Vamsi Excel Programming 4 March 3rd 09 01:29 PM
Conflict with valid range reference error smaruzzi Excel Discussion (Misc queries) 1 March 14th 07 10:05 PM
Input cell reference is not valid (One Variable Data Table) Dottore Excel Worksheet Functions 9 September 1st 05 03:05 PM
Determine Valid Sample Size from a Population - Any UDFs or Formulas? DataFreakFromUtah Excel Programming 0 September 13th 04 06:19 PM


All times are GMT +1. The time now is 03:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"