Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

how to test if range object target deleted

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob Flanagan - 25 Jan 2008 20:43 GMT
I did the following:
Sub test()
   Dim cell As Range
   Set cell = ActiveCell
   ActiveCell.EntireRow.Delete
   If cell Is Nothing Then
       MsgBox "row deleted"
   Else
       MsgBox "cell variable is not nothing!"
   End If
End Sub

The answer I got was "cell variable is not nothing!".

Question:  how to check for the variable cell no longer existing?  I know I
can do the following:

dim anyS as string
on error resume next
anys =""
anys = cell.address
on error goto 0
if anys ="" then
   msgbox "cell is nothing"
end if

But there should be a cleaner way! Excel 2003

Bob
Peter T - 25 Jan 2008 22:36 GMT
Hi  Bob,

Having assigned an object to an object to a variable, deleting the object
does not remove the variable pointer from memory and so the variable will
continue to be 'not nothing'.  You can confirm that with objptr(cell).
I doubt there is a cleaner way to test if the object still exists other than
to attempt to refer to one of the variable's anticipated properties under an
error handler, though I suspect there is an API approach.  I think the
method you posted is just fine!

Regards,
Peter T

>I did the following:
> Sub test()
[quoted text clipped - 25 lines]
>
> Bob
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.