I have a UDF with an optional *range* parameter, and whether one block of
code should run depends on whether or not a range was supplied.
I tried ISMISSING(OptionalRangeParameter) but even when the range is not
passed through, it apparently doesn't evaluate as missing.
I also tried ISNULL and ISEMPTY, to the same effect.
I also tried the ubound>lbound trick for arrays, but that didn't work
(presumably because this is a range, or because the parameter hadn't been
passed in the first place, I'm not sure)
What is the most reliable method of determining if an optional range
parameter was used?
When the parameter isn't used and my code processes anyway, it causes my
code to ungracefully fail when trying to set an array equal the the values in
the (optional) range.
Thanks!
Keith
Code:
Function ParseDataForJerry(StrSourceRange As Range, Optional MatchListRng As
Range, Optional CharFormat As String)
'StrSourceRange As Range: This is the cell with the irregularly
formatted source data
'Optional MatchListRng As Range: This is a list that contains possible matches
'Optional CharFormat As String: This is searching for only a single,
specific format
If Not (IsMissing(MatchListRng)) Then
Dim cList As Variant
cList = MatchListRng.Value <--runs and fails here even when parameter is
empty
End If
....code continues
|
|
0
|
|
|
|
Reply
|
Utf
|
6/2/2010 11:04:12 PM |
|
What is the Address property of a missing range? Can you test for it?
--
Gary''s Student - gsnu201003
"ker_01" wrote:
> I have a UDF with an optional *range* parameter, and whether one block of
> code should run depends on whether or not a range was supplied.
>
> I tried ISMISSING(OptionalRangeParameter) but even when the range is not
> passed through, it apparently doesn't evaluate as missing.
>
> I also tried ISNULL and ISEMPTY, to the same effect.
>
> I also tried the ubound>lbound trick for arrays, but that didn't work
> (presumably because this is a range, or because the parameter hadn't been
> passed in the first place, I'm not sure)
>
> What is the most reliable method of determining if an optional range
> parameter was used?
>
> When the parameter isn't used and my code processes anyway, it causes my
> code to ungracefully fail when trying to set an array equal the the values in
> the (optional) range.
>
> Thanks!
> Keith
>
> Code:
> Function ParseDataForJerry(StrSourceRange As Range, Optional MatchListRng As
> Range, Optional CharFormat As String)
>
> 'StrSourceRange As Range: This is the cell with the irregularly
> formatted source data
> 'Optional MatchListRng As Range: This is a list that contains possible matches
> 'Optional CharFormat As String: This is searching for only a single,
> specific format
>
> If Not (IsMissing(MatchListRng)) Then
> Dim cList As Variant
> cList = MatchListRng.Value <--runs and fails here even when parameter is
> empty
> End If
>
> ...code continues
|
|
0
|
|
|
|
Reply
|
Utf
|
6/2/2010 11:16:01 PM
|
|
This is from xl2003 VBA's help for IsMissing:
Returns a Boolean value indicating whether an optional Variant argument has been
passed to a procedure.
So you'll want to use something like:
Option Explicit
Function myFunc(Optional myRng As Variant) As Double
If IsMissing(myRng) Then
'do something
myFunc = -9999
ElseIf TypeName(myRng) = "Range" Then
'do something with a range
myFunc = Application.Sum(myRng)
Else
'do something else???
End If
End Function
Sub testme()
MsgBox myFunc
MsgBox myFunc(ActiveSheet.Range("A1:a3"))
End Sub
ker_01 wrote:
>
> I have a UDF with an optional *range* parameter, and whether one block of
> code should run depends on whether or not a range was supplied.
>
> I tried ISMISSING(OptionalRangeParameter) but even when the range is not
> passed through, it apparently doesn't evaluate as missing.
>
> I also tried ISNULL and ISEMPTY, to the same effect.
>
> I also tried the ubound>lbound trick for arrays, but that didn't work
> (presumably because this is a range, or because the parameter hadn't been
> passed in the first place, I'm not sure)
>
> What is the most reliable method of determining if an optional range
> parameter was used?
>
> When the parameter isn't used and my code processes anyway, it causes my
> code to ungracefully fail when trying to set an array equal the the values in
> the (optional) range.
>
> Thanks!
> Keith
>
> Code:
> Function ParseDataForJerry(StrSourceRange As Range, Optional MatchListRng As
> Range, Optional CharFormat As String)
>
> 'StrSourceRange As Range: This is the cell with the irregularly
> formatted source data
> 'Optional MatchListRng As Range: This is a list that contains possible matches
> 'Optional CharFormat As String: This is searching for only a single,
> specific format
>
> If Not (IsMissing(MatchListRng)) Then
> Dim cList As Variant
> cList = MatchListRng.Value <--runs and fails here even when parameter is
> empty
> End If
>
> ...code continues
--
Dave Peterson
|
|
0
|
|
|
|
Reply
|
Dave
|
6/2/2010 11:16:30 PM
|
|
When you delcare this as a Range object; try this instead......
If Not MatchListRng Is Nothing Then
End If
--
Jacob (MVP - Excel)
"ker_01" wrote:
> I have a UDF with an optional *range* parameter, and whether one block of
> code should run depends on whether or not a range was supplied.
>
> I tried ISMISSING(OptionalRangeParameter) but even when the range is not
> passed through, it apparently doesn't evaluate as missing.
>
> I also tried ISNULL and ISEMPTY, to the same effect.
>
> I also tried the ubound>lbound trick for arrays, but that didn't work
> (presumably because this is a range, or because the parameter hadn't been
> passed in the first place, I'm not sure)
>
> What is the most reliable method of determining if an optional range
> parameter was used?
>
> When the parameter isn't used and my code processes anyway, it causes my
> code to ungracefully fail when trying to set an array equal the the values in
> the (optional) range.
>
> Thanks!
> Keith
>
> Code:
> Function ParseDataForJerry(StrSourceRange As Range, Optional MatchListRng As
> Range, Optional CharFormat As String)
>
> 'StrSourceRange As Range: This is the cell with the irregularly
> formatted source data
> 'Optional MatchListRng As Range: This is a list that contains possible matches
> 'Optional CharFormat As String: This is searching for only a single,
> specific format
>
> If Not (IsMissing(MatchListRng)) Then
> Dim cList As Variant
> cList = MatchListRng.Value <--runs and fails here even when parameter is
> empty
> End If
>
> ...code continues
|
|
0
|
|
|
|
Reply
|
Utf
|
6/3/2010 5:01:39 AM
|
|
|
3 Replies
441 Views
(page loaded in 0.07 seconds)
Similiar Articles: file with udf extension - microsoft.public.excel.miscmicrosoft.public.excel.programming - page 12 UDF: how to tell if optional *range* parameter is empty? Utf 3 203 I have a UDF ... Finding File Extension from Full Filename ... microsoft.public.excel.programming - page 12UDF: how to tell if optional *range* parameter is empty? Utf 3 212 I have a UDF with an optional *range* parameter, and whether one block of code should run depends ... Optional IN Clause parameter - microsoft.public.sqlserver ...... do not take parameters, I need to use a UDF like ... to accomplish is to have @DeptNames as an optional parameter. ... have to send off this week; I will let you know ... named range in macro call - microsoft.public.excel.programming ...... generic macro that accepted a range of data as an input parameter ... Paste to next empty cell in named range of cells - microsoft ... ... Can a VBA UDF tell who called it ... enumerating empty groups - microsoft.public.windows.powershell ...Can anyone tell me how I can list all empty AD groups? ... Hi Salty, Use the -Empty parameter ... the mandatory and optional properties ... enumerating empty groups ... Writting ACCESS table to Excel - microsoft.public.access ...& vbNewLine _ & "(Recordset is empty ... The 2nd parameter provides feedback to the caller ... are a few tips (which you may already know): 1. The Excel Range ... XML vs SQL Server - microsoft.public.dotnet.languages.csharp ...In relation to other database options ... The true is if ... at no cost, if SQL Server were out of his cost range. ... (Yes, I know there may be a missing index on the Sql ... WinDbg: Unable to get verifier list - microsoft.public.windowsxp ...You don't have to tell me twice about that, as the ... IN_NONPAGED_AREA Bug Check Code : 0x10000050 Parameter ... recent generations of hard drives in the 1TB range. Opening up in RichTextBox2 ? - microsoft.public.dotnet.languages ...... original "ogimet.txt" file it is now empty 0 KB. What's causing this? I know ... The program should probably have options for ... then we can look at how to track date range ... Not refreshing - microsoft.public.dotnet.framework.aspnet ...Does anyone know what I could be looking at to get IE ... I have a conditional format (fill on a range of 9 cells ... They are simple "IF" formulas. If I press F9 or Options ... UDF: how to tell if optional *range* parameter is empty? ExcelI have a UDF with an optional *range* parameter, and whether one block of code should run depends on whether or not a range was supplied. I tried ISMISSI .net - VB.NET COM Server implementing Excel UDF not callable with ...... Answer Regarding Optional Range Parameters. I still don't know why ... with your user-defined function (UDF) using the same exact parameter signature ... String.Empty ... Chapter 10: Client Support For Server UDFs... will not know about it. The parameter this new ... When the parameter is a reference to a cell or a range, Excel ... example, if the parameter is an integer, and there is an empty ... Wrox Article : Excel Services User-Defined Functions (UDFs) - WroxEMPTY: Numeric: Tries to cast; Byte and ... represent the cell count in that range. =ReturnNumberOfCells(E5:H6) Parameter ... the UDF by clicking the Add User-Defined Function ... Excel User-Defined Functions - Decision ModelsIf you develop a User Defined Function (UDF ... ' a calculated parameter is Empty if it ... use multiple (optional if there are a varying number) range arguments ... 7/25/2012 6:44:41 PM
|