Optional argument of a procedure that takes Range values

secici

New Member
Joined
Sep 21, 2002
Messages
43
Hi!

I' ve written a procedure that takes following formal parameters

Private Sub FetchInfo(ByRef InfoSource As Range, ByRef InfoTarget As Range, Optional ByVal DetailField As Range = Range("IV65536"))

The Help says that :
Note IsMissing does not work on simple data types (such as Integer or Double) because ....

so I can't use IsMissing function to test the optional argument. It recommends to use a "specialvalue" like this :

Sub MySub(Optional MyVar As String = "specialvalue")
If MyVar = "specialvalue" Then
' MyVar was omitted.
Else
...
End Sub

But the compiler fails in my procedure and says that -Range("IV65536")- statement is not constant.

How can I test an optional range object if it is passed as an argument or not?

Thanks...
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Mudface

MrExcel MVP
Joined
Feb 18, 2002
Messages
3,339
I think if you try passing an object (such as a Range) to a procedure as an optional parameter, the default value can only be set to Nothing. A workaround might be to use DetailField as a String and then use Range(DetailField) in your FetchInfo sub: -

Private Sub FetchInfo(ByRef InfoSource As Range, ByRef InfoTarget As Range, Optional ByVal DetailField As String = "IV65536")
This message was edited by Mudface on 2002-10-25 05:53
 

Forum statistics

Threads
1,144,291
Messages
5,723,532
Members
422,502
Latest member
barakgahtan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top