LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default Vartype() and vbObject

HI All,
I'm learning/testing with the vartype function and using variants in
called sub procs.

Code below is parts of larger macros. Sub Test2 processes TestVar variable
depending on its type.

1. In sub Test1, why is vartype of a cell range 8204? Seems 'odd'. The
help shows 8192 for an array and 12 for vbVariant. Help is silent on why a
cell range's vartype is not vbObject.

2. With more digging, I found the TypeName function.
Is: If "Range" = typename(TestVar) then .....

a 'good' way to check for a cell range object ?

3. Assuming an array is NOT a variant array containing different data
types in its elements, are the statements below roughly equivalent to test
for a numeric array ? (e.g. integer or long)
(Note: Coding efficiency not a consideration here)

Dim Name as string
Dim TestAy As Variant
'code establishing TestAy's element values

if isarray(TestAy) then if isnumeric(TestAy(1)) then .... '#1 assumes
base 1 option.

if "*()" like typename(TestAy) then '#2
name = typename(TestAy)
if instr("InteLong", left(name,4)) 0 then .....
end if

Thanks.
------------


sub Test1()
Dim TstRng As Range

Set TstRng = ActiveSheet.Range("p146:w146")
MsgBox VarType(TstRng), , "ActiveSheet.Range(p146:w146)" 'got 8204

call Test2(TstRng)
end sub



sub Test2(TestVar as variant)

if vartype(testvar) = vbstring then
'not shown code works when testvar is string

elseif vartype(testvar) = vbarray + vbinteger then
'not shown code works when testvar is integer array

elseif vartype(testvar) = vbobject then
'thought i'd get sub Test1's TstRng here, but did not.
'using TypeName(testvar) worked.
else
msgbox "Error vartype " & vartype(testvar) 'tested ok with "bad" input
end if
end sub
--
Neal Z
 
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
Passing variable to VarType of other Variable ExcelMonkey[_190_] Excel Programming 3 February 22nd 05 01:38 PM
Question about VarType [email protected] Excel Programming 2 August 7th 03 01:21 AM


All times are GMT +1. The time now is 09:30 AM.

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"