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

Having a problem getting to "Range" objects to test as equivalent. In the
simplified code below after calling Sub One and then Sub Two with the same
"Range" argument the MsgBox displayed the addresses of X and C as the same,
but failed to evaluate the Object X and C as being equivalent.

What's wrong with the code?
(Of course this assumes my simplified code below accurately represents my
actual code :-)

Simplified code:

Sub One (ByVal A As Range)
Call Test(A, True)
End Sub

Sub Two(ByVal B As Range)
Call Test(B, False)
End Sub

Sub Test(ByVal X as Range, Flag As Boolean)
Static C As Range

MsgBox X.Address & " " & C.Address
' After Second Call to Test both addresses show the same value.

Select Case Flag
Case Is = True
Set C = X
Case Is = False
If X Is C Then
MsgBox "X is C"
Else
MsgBox "X is not C"
End If
End Select
End Sub

Call One(R) ' Where R is a cell reference (Range).
Call Two(R) ' Where R is same cell reference.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Object Is Object evaluation problem

Test whether R.Address = C.Address.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"mickey" wrote in message
...
Having a problem getting to "Range" objects to test as equivalent. In the
simplified code below after calling Sub One and then Sub Two with the same
"Range" argument the MsgBox displayed the addresses of X and C as the
same,
but failed to evaluate the Object X and C as being equivalent.

What's wrong with the code?
(Of course this assumes my simplified code below accurately represents my
actual code :-)

Simplified code:

Sub One (ByVal A As Range)
Call Test(A, True)
End Sub

Sub Two(ByVal B As Range)
Call Test(B, False)
End Sub

Sub Test(ByVal X as Range, Flag As Boolean)
Static C As Range

MsgBox X.Address & " " & C.Address
' After Second Call to Test both addresses show the same value.

Select Case Flag
Case Is = True
Set C = X
Case Is = False
If X Is C Then
MsgBox "X is C"
Else
MsgBox "X is not C"
End If
End Select
End Sub

Call One(R) ' Where R is a cell reference (Range).
Call Two(R) ' Where R is same cell reference.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Object Is Object evaluation problem

Actually, that's what I ended up doing, but I was just wondering if anyone
knew why the Object comparison apparently failed.

Thanks for your response.


"Jon Peltier" wrote:

Test whether R.Address = C.Address.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"mickey" wrote in message
...
Having a problem getting to "Range" objects to test as equivalent. In the
simplified code below after calling Sub One and then Sub Two with the same
"Range" argument the MsgBox displayed the addresses of X and C as the
same,
but failed to evaluate the Object X and C as being equivalent.

What's wrong with the code?
(Of course this assumes my simplified code below accurately represents my
actual code :-)

Simplified code:

Sub One (ByVal A As Range)
Call Test(A, True)
End Sub

Sub Two(ByVal B As Range)
Call Test(B, False)
End Sub

Sub Test(ByVal X as Range, Flag As Boolean)
Static C As Range

MsgBox X.Address & " " & C.Address
' After Second Call to Test both addresses show the same value.

Select Case Flag
Case Is = True
Set C = X
Case Is = False
If X Is C Then
MsgBox "X is C"
Else
MsgBox "X is not C"
End If
End Select
End Sub

Call One(R) ' Where R is a cell reference (Range).
Call Two(R) ' Where R is same cell reference.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Object Is Object evaluation problem

They've never worked this way as far as I can remember, so without bothering
to wonder why (it's MS & XL after all), I just learned what worked.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"mickey" wrote in message
...
Actually, that's what I ended up doing, but I was just wondering if anyone
knew why the Object comparison apparently failed.

Thanks for your response.


"Jon Peltier" wrote:

Test whether R.Address = C.Address.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"mickey" wrote in message
...
Having a problem getting to "Range" objects to test as equivalent. In
the
simplified code below after calling Sub One and then Sub Two with the
same
"Range" argument the MsgBox displayed the addresses of X and C as the
same,
but failed to evaluate the Object X and C as being equivalent.

What's wrong with the code?
(Of course this assumes my simplified code below accurately represents
my
actual code :-)

Simplified code:

Sub One (ByVal A As Range)
Call Test(A, True)
End Sub

Sub Two(ByVal B As Range)
Call Test(B, False)
End Sub

Sub Test(ByVal X as Range, Flag As Boolean)
Static C As Range

MsgBox X.Address & " " & C.Address
' After Second Call to Test both addresses show the same value.

Select Case Flag
Case Is = True
Set C = X
Case Is = False
If X Is C Then
MsgBox "X is C"
Else
MsgBox "X is not C"
End If
End Select
End Sub

Call One(R) ' Where R is a cell reference (Range).
Call Two(R) ' Where R is same cell reference.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Object Is Object evaluation problem

In fact, a lot of these object comparisons don't work. You have to resort to
approaches like this:

Worksheets:
If wksA.Name = wksB.Name Then

Workbooks
If WbkA.Name = wbkB.Name Then

etc.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"mickey" wrote in message
...
Actually, that's what I ended up doing, but I was just wondering if anyone
knew why the Object comparison apparently failed.

Thanks for your response.


"Jon Peltier" wrote:

Test whether R.Address = C.Address.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"mickey" wrote in message
...
Having a problem getting to "Range" objects to test as equivalent. In
the
simplified code below after calling Sub One and then Sub Two with the
same
"Range" argument the MsgBox displayed the addresses of X and C as the
same,
but failed to evaluate the Object X and C as being equivalent.

What's wrong with the code?
(Of course this assumes my simplified code below accurately represents
my
actual code :-)

Simplified code:

Sub One (ByVal A As Range)
Call Test(A, True)
End Sub

Sub Two(ByVal B As Range)
Call Test(B, False)
End Sub

Sub Test(ByVal X as Range, Flag As Boolean)
Static C As Range

MsgBox X.Address & " " & C.Address
' After Second Call to Test both addresses show the same value.

Select Case Flag
Case Is = True
Set C = X
Case Is = False
If X Is C Then
MsgBox "X is C"
Else
MsgBox "X is not C"
End If
End Select
End Sub

Call One(R) ' Where R is a cell reference (Range).
Call Two(R) ' Where R is same cell reference.








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
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Option button object proeprties or object not found in vba Pete Straman S via OfficeKB.com Excel Programming 0 August 31st 05 05:49 PM
Confusion about how the Window object fits into the Excel object model Josh Sale Excel Programming 11 April 15th 05 06:08 PM
Range object to Array object conversion Myrna Larson[_2_] Excel Programming 1 August 1st 03 02:27 AM


All times are GMT +1. The time now is 07:36 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"