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: 71
Default Why isn't range variable nothing in this case

Put the following code in a workbook:

Sub VariableTest()
Dim anyR As Range
Set anyR = Selection
anyR.Parent.Parent.Close False
If anyR Is Nothing Then
MsgBox "is nothing"
Else
MsgBox "is Not nothing"
End If
End Sub

Now go to another workbook and run it. Since the workbook which anyR
pointed to is now closed, I expected anyR to be nothing. But it is not.

What I want to do is to test if the workbook has been closed by seeing if
anyR is nothing. The only way I see is something like this:

dim wS as worksheet
On Error Resume next
set wS = nothing 'in case it has previously been set
set wS = anyR.Parent
On Error goto 0

I can then test if wS is nothing.

I would much prefer a test directly on the range variable without using an
error trap, as it is easy to forget to remove an error trap. And the above
is several lines of code (I can always put in a function) Is there a way to
do a direct test?

Bob


 
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
Variable Case issue J Streger Excel Programming 6 December 21st 07 04:41 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Case statement in variable range TP[_3_] Excel Programming 1 August 23rd 03 05:14 PM
Problem with copying variable(s) to cell(s) and converting strings to mixed case Don Glass Excel Programming 4 August 17th 03 09:46 PM


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