IsArray on Variant/Object/Range returns true??

Q

QuantDev

Any idea on how I can check if the variant contains an array,
considered IsArray returns true for ranges?

thanks
 
J

Jake Marx

Hi QuantDev,
Any idea on how I can check if the variant contains an array,
considered IsArray returns true for ranges?

If the variable is truly a Variant, then it cannot contain a reference to a
Range object. When you do this:

Dim v As Variant

v = Range("A1:A10")

The variable v is being filled with the *values* from the range A1:A10. So
the IsArray function is correct - the Variant v really does contain an array
at that point.

Maybe I'm not understanding your issue - what is it you are trying to
accomplish?

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
S

Stan Scott

Function TestArray(a)
TestArray = True
On Error Resume Next
If IsError(UBound(a)) Then
TestArray = False
End If
End Function

Stan Scott
New York City
 
T

Tom Ogilvy

Check for a range first

if typename(varr) is "Range" then
' it's a range
elseif isarray(varr) then
' it's an array
 
T

Tom Ogilvy

Dim v as Variant
set v = Range("A1:A10")

v will hold a range reference.

I assume he has a generalized function that is passed in a variant which may
contain a range. This would be a common need in handling a parmarray

--
Regards,
Tom Ogilvy

Jake Marx said:
Hi QuantDev,
Any idea on how I can check if the variant contains an array,
considered IsArray returns true for ranges?

If the variable is truly a Variant, then it cannot contain a reference to a
Range object. When you do this:

Dim v As Variant

v = Range("A1:A10")

The variable v is being filled with the *values* from the range A1:A10. So
the IsArray function is correct - the Variant v really does contain an array
at that point.

Maybe I'm not understanding your issue - what is it you are trying to
accomplish?

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
Q

QuantDev

Stan Scott said:
Function TestArray(a)
TestArray = True
On Error Resume Next
If IsError(UBound(a)) Then
TestArray = False
End If
End Function

I suppose it would return false for 0 dimensioned arrays.
 
Q

QuantDev

Tom Ogilvy said:
Check for a range first

if typename(varr) is "Range" then
' it's a range
elseif isarray(varr) then
' it's an array

--

Thanks Tom.

As far as you know, am I going to get "true" for isarray for others
variant/object/* combinations?
thx
 
T

Tom Ogilvy

for example:

? isarray(thisworkbook.Sheets)
False
? isarray(Activesheet.Shapes)
False
? isarray(Range("A1"))
False
? isarray(Range("A1:A10"))
True

I can't think of another object that returns an array for the value (or
default) attribute. That doesn't mean there are not any, but I can't think
of one.
 
Top