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

I ran into a proble trying to set a declared object variable to a value,
like this:

Dim ObjVar1, ObjVar2 As Object

With Range("MyRange")
Set ObjVar1 = .Find(x)
ObjVar2 = ObjVar1.Address
End With
Range(ObjVar2).Activate

The problem has to do with the fact that the second object variable was set
to Nothing by default, and I don't know how to set it to Empty which is what
I have to do to in order to get it to accept a value. I've gone around the
problem by setting it to a Variant data type, and I know I can go around it
by not declaring it in the first place, but I am curious to find out why
ObjVar1 in the declaration statment is set to Empty and ObjVar2 is set to
nothing, try this:

Paste this code into VBA and step into it. Look at the value of objMyObject
and objMyObject1 and explain to me why they are not both Empty.

Sub test()
Dim objMyObject, objMyObject2 As Object
End Sub

Thanks







  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Object variables

You must declare each vars explicitly....

Dim ObjVar1, ObjVar2 As Object

results in ObjVar1 being set to Variant; and ObjVar2 as an Object

Use:

Dim ObjVar1 As Object, ObjVar2 As Object


Cheers
N

"scarbrough" wrote in message
news:UGdAb.68591$m24.26909@fed1read02...
I ran into a proble trying to set a declared object variable to a value,
like this:

Dim ObjVar1, ObjVar2 As Object

With Range("MyRange")
Set ObjVar1 = .Find(x)
ObjVar2 = ObjVar1.Address
End With
Range(ObjVar2).Activate

The problem has to do with the fact that the second object variable was

set
to Nothing by default, and I don't know how to set it to Empty which is

what
I have to do to in order to get it to accept a value. I've gone around

the
problem by setting it to a Variant data type, and I know I can go around

it
by not declaring it in the first place, but I am curious to find out why
ObjVar1 in the declaration statment is set to Empty and ObjVar2 is set to
nothing, try this:

Paste this code into VBA and step into it. Look at the value of

objMyObject
and objMyObject1 and explain to me why they are not both Empty.

Sub test()
Dim objMyObject, objMyObject2 As Object
End Sub

Thanks











----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
  #3   Report Post  
Posted to microsoft.public.excel.programming
raj raj is offline
external usenet poster
 
Posts: 32
Default Object variables

Brad,

This may do what you want, but "MyRange" would have to be
a named range in the sheet:

Dim rngVar1 As Range
Dim strVar2 As String

With Range("MyRange")
Set rngVar1 = .Find(x)
strVar2 = rngVar1.Address
End With
Range(strVar2).Activate


-----Original Message-----
I ran into a proble trying to set a declared object

variable to a value,
like this:

Dim ObjVar1, ObjVar2 As Object

With Range("MyRange")
Set ObjVar1 = .Find(x)
ObjVar2 = ObjVar1.Address
End With
Range(ObjVar2).Activate

The problem has to do with the fact that the second

object variable was set
to Nothing by default, and I don't know how to set it to

Empty which is what
I have to do to in order to get it to accept a value.

I've gone around the
problem by setting it to a Variant data type, and I know

I can go around it
by not declaring it in the first place, but I am curious

to find out why
ObjVar1 in the declaration statment is set to Empty and

ObjVar2 is set to
nothing, try this:

Paste this code into VBA and step into it. Look at the

value of objMyObject
and objMyObject1 and explain to me why they are not both

Empty.

Sub test()
Dim objMyObject, objMyObject2 As Object
End Sub

Thanks







.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Object variables

The address property is a string, so you should declare your variables such

Dim ObjVar1 As Object, ObjVar2 As String

With Range("MyRange")
Set ObjVar1 = .Find(x)
ObjVar2 = ObjVar1.Address
End With
If Not IsEmpty(ObjVar2) Then
Range(ObjVar2).Activate
End If


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"scarbrough" wrote in message
news:UGdAb.68591$m24.26909@fed1read02...
I ran into a proble trying to set a declared object variable to a value,
like this:

Dim ObjVar1, ObjVar2 As Object

With Range("MyRange")
Set ObjVar1 = .Find(x)
ObjVar2 = ObjVar1.Address
End With
Range(ObjVar2).Activate

The problem has to do with the fact that the second object variable was

set
to Nothing by default, and I don't know how to set it to Empty which is

what
I have to do to in order to get it to accept a value. I've gone around

the
problem by setting it to a Variant data type, and I know I can go around

it
by not declaring it in the first place, but I am curious to find out why
ObjVar1 in the declaration statment is set to Empty and ObjVar2 is set to
nothing, try this:

Paste this code into VBA and step into it. Look at the value of

objMyObject
and objMyObject1 and explain to me why they are not both Empty.

Sub test()
Dim objMyObject, objMyObject2 As Object
End Sub

Thanks









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
2 Label Options - Forms Object vs Control Box Object Awrex Excel Discussion (Misc queries) 3 July 17th 09 07:10 PM
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Creating Object Variables - and passing them as arguements Ian Stanborough Excel Programming 3 November 11th 03 02:28 PM
Range object to Array object conversion Myrna Larson[_2_] Excel Programming 1 August 1st 03 02:27 AM
Range object to Array object conversion Alan Beban[_3_] Excel Programming 0 August 1st 03 01:24 AM


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

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"