ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Testing for existence of range (https://www.excelbanter.com/excel-programming/282831-testing-existence-range.html)

David

Testing for existence of range
 
Greetings,
TIA for any help
In the sub below, how can i test for the existence of the
Range referred to in rng
<rng is nothing seems to be the wrong idea.
Sub Test()
Dim rng As Range
Set rng = Range("A1, A4, A6, A8")
rng.EntireRow.Select
Selection.Delete
MsgBox rng Is Nothing ' returns 'False'
End Sub

gocush[_15_]

Testing for existence of range
 

Not exactly sure of your question.
If you change the line of you code

Msgbox rng is nothing

to:
Set rng = Nothing

then the code is good.

Your question - how do I test for the existence of the Range
"rng" It exists when you create it with your Set statement.

Maybe your question is how do I check for the values in the rng?

Can you clarify

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com


David

Testing for existence of range
 
Thanks for your response
Let's say I start off with
<Dim rng as range
Set rng = Range("A1:A3")
Now I delete Rows 1 to 3
The contents of rng have now disappeared
How do I test that the contents of range have dissapeared?
TIA

Tom Ogilvy

Testing for existence of range
 
set rng = rows("1:3")
rng.Delete
on Error resume next
msgbox rng.Address
if err.number < 0 then
msgbox "rng has been deleted"
err.clear
set rng = nothing
End if
On Error goto 0


rng is not nothing - but the object it referred to is gone.

--
Regards,
Tom Ogilvy

"David" wrote in message
...
Thanks for your response
Let's say I start off with
<Dim rng as range
Set rng = Range("A1:A3")
Now I delete Rows 1 to 3
The contents of rng have now disappeared
How do I test that the contents of range have dissapeared?
TIA




David

Testing for existence of range
 
Tom,
Thanks for coming to my rescue once more


All times are GMT +1. The time now is 12:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com