Checking to see if a Range Object exists?

  • Thread starter Thread starter debartsa
  • Start date Start date
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
 
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
 
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
 
Back
Top