Checking to see if a Range Object exists?

D

debartsa

Hi Everybody,

I'm using Excel 97 with VBA... Is there a way to programmatically check if a
named Range exists

i.e. I want to access ===> ActiveSheet.Range("Activity") <==== only
if it exists. The problem is it'll crash referencing this if it doesn't
exit?

Thanks for any help!
Sam
 
R

Ron de Bruin

Hi debartsa

One way

Sub test()
Set Source = Nothing
On Error Resume Next
Set Source = Range("Activity")
On Error GoTo 0
If Source Is Nothing Then
MsgBox "The range don't exist.", _
vbOKOnly, "Hello"
Else
Range("Activity").Select
End If
End Sub
 
D

debartsa

Thanks Ron,

I'll give it a try!

Sam


Ron de Bruin said:
Hi debartsa

One way

Sub test()
Set Source = Nothing
On Error Resume Next
Set Source = Range("Activity")
On Error GoTo 0
If Source Is Nothing Then
MsgBox "The range don't exist.", _
vbOKOnly, "Hello"
Else
Range("Activity").Select
End If
End Sub
 
Top