Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Variable type

It is claimed that, after

Set rng = Range("C1:C3")

with no variable declaration, rng is a Variant containing a Range type
variable of the same name, rather than that rng is simply a Range type
variable.

1. How can this claim be tested?

2. Under what circumstances would it ever make a difference?

Simply using Typename to resolve the difference is not definitive,
because part of the claim is that Typename(rng) returns the type of the
Range type variable within the Variant rather than the type of the Variant.

Alan Beban
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Variable type

Alan,

The only way I can think of to test whether Rng is declared explicitly as a
Range rather than as a Varaint is to attempt to set Rng to another type of
object. If this does not cause an error, then Rng is a Variant. If it fails,
Rng is declared as a Range. For example,

Sub AAA()
Dim R1 ' Variant
Dim R2 As Range

Set R1 = Range("A1")
Set R2 = Range("A1")

On Error Resume Next
Err.Clear
Set R1 = Worksheets(1)
If Err.Number < 0 Then
Debug.Print "R1 Is Not A Variant"
Else
Debug.Print "R1 Is A Variant"
End If

Err.Clear
Set R2 = Worksheets(1)
If Err.Number < 0 Then
Debug.Print "R2 Is Not A Variant"
Else
Debug.Print "R2 Is A Variant"
End If
End Sub

In this code, the result is that R1 is recognized as a Variant because
setting it to a Worksheet does not raise an error. R2 is recognized as Range
because you get an error 13 Type Mismatch when attempting to set it to a
Worksheet.

In the real world, though, I'm not sure that the distinction is meaningful.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Alan Beban" wrote in message
...
It is claimed that, after

Set rng = Range("C1:C3")

with no variable declaration, rng is a Variant containing a Range type
variable of the same name, rather than that rng is simply a Range type
variable.

1. How can this claim be tested?

2. Under what circumstances would it ever make a difference?

Simply using Typename to resolve the difference is not definitive, because
part of the claim is that Typename(rng) returns the type of the Range type
variable within the Variant rather than the type of the Variant.

Alan Beban


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Variable type

Thanks, Chip.

Alan Beban

Chip Pearson wrote:
Alan,

The only way I can think of to test whether Rng is declared explicitly
as a Range rather than as a Variant is to attempt to set Rng to another
type of object. If this does not cause an error, then Rng is a Variant.
If it fails, Rng is declared as a Range. . . .

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
Type of variable J@Y Excel Programming 3 August 14th 07 04:14 PM
Variable type Confusion D Zandveld Excel Programming 2 March 5th 07 09:07 AM
What data type for Variable? Jeff Armstrong Excel Programming 4 August 6th 04 09:38 PM
type variable as argument of a sub Koos Excel Programming 1 October 23rd 03 11:41 AM
Variable Type - help me to solve this choco140 Excel Programming 1 September 28th 03 10:39 AM


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

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"