Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Test for Optional and Asign one Range to another

Below is a snipit of a function I am having trouble with... I am
tyring to write a function that gets passed 1 or 2 ranges. I cant seem
to get the optional test to work right. Also how do I asign one range
to another. Basicly if only one range is passed to the fuction I want
to set the optional range equal to the one required range, Any help
would be appreciated it.
Thanks.

Function temp(rng As Range, rngoffset As Range, Optional rngoffset As
Variant)

If IsEmpty(rngoffset) Is True Then

Debug.Print "rngoffset empty"
Set rngoffset = rng
End If

End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Test for Optional and Asign one Range to another

rngOffset is declared twice as the function argument.
--
If this post helps click Yes
---------------
Jacob Skaria


"Michael" wrote:

Below is a snipit of a function I am having trouble with... I am
tyring to write a function that gets passed 1 or 2 ranges. I cant seem
to get the optional test to work right. Also how do I asign one range
to another. Basicly if only one range is passed to the fuction I want
to set the optional range equal to the one required range, Any help
would be appreciated it.
Thanks.

Function temp(rng As Range, rngoffset As Range, Optional rngoffset As
Variant)

If IsEmpty(rngoffset) Is True Then

Debug.Print "rngoffset empty"
Set rngoffset = rng
End If

End Function

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Test for Optional and Asign one Range to another

Something like the following should get you started:

Function Temp(R1 As Range, Optional ByVal R2 As Range = Nothing) As
Variant
If Not R1 Is Nothing Then
Temp = CVErr(xlErrRef) ' required range was nothing
Exit Function
End If
If R2 Is Nothing Then
' R2 as omitted.
Set R2 = R1
Else
' R2 was passed
End If

Temp = some_result
End Function

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Mon, 30 Mar 2009 05:11:54 -0700 (PDT), Michael
wrote:

Below is a snipit of a function I am having trouble with... I am
tyring to write a function that gets passed 1 or 2 ranges. I cant seem
to get the optional test to work right. Also how do I asign one range
to another. Basicly if only one range is passed to the fuction I want
to set the optional range equal to the one required range, Any help
would be appreciated it.
Thanks.

Function temp(rng As Range, rngoffset As Range, Optional rngoffset As
Variant)

If IsEmpty(rngoffset) Is True Then

Debug.Print "rngoffset empty"
Set rngoffset = rng
End If

End Function

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Test for Optional and Asign one Range to another

Declare your Function (or Sub) this way...

Function temp(rng As Range, Optional rngoffset As Variant)

and use this to test if the Optional argument was passed into the function
(or Sub) or not....

If IsMissing(rngoffset) Then
MsgBox "The Optional argument is missing"
Else
MsgBox "The Optional argument was passed"
End If

Note the use of IsMissing as the testing mechanism.

--
Rick (MVP - Excel)


"Michael" wrote in message
...
Below is a snipit of a function I am having trouble with... I am
tyring to write a function that gets passed 1 or 2 ranges. I cant seem
to get the optional test to work right. Also how do I asign one range
to another. Basicly if only one range is passed to the fuction I want
to set the optional range equal to the one required range, Any help
would be appreciated it.
Thanks.

Function temp(rng As Range, rngoffset As Range, Optional rngoffset As
Variant)

If IsEmpty(rngoffset) Is True Then

Debug.Print "rngoffset empty"
Set rngoffset = rng
End If

End Function


Reply
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
asign a number to a text string gimme_donuts Excel Discussion (Misc queries) 7 December 24th 08 07:21 AM
asign the next 10th as the due date. slow but sure Excel Worksheet Functions 4 June 16th 08 02:23 AM
HOW TO ASIGN SAME NAME TO TWO DIFFERENT RANGES IN SEPARAT SHEETS Satyapal Kaushal Excel Discussion (Misc queries) 1 June 5th 07 01:31 PM
Asign Array Variant to Column William C. Smith Excel Programming 3 December 27th 03 04:20 AM


All times are GMT +1. The time now is 10:50 AM.

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

About Us

"It's about Microsoft Excel"