Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Check if named range exists!

Hi all

trying to find a solution to the following small problem. I need to check to
see if a named range exists, if it does I then need to delete it, if it
doesnt I need to exit sub
The following code is what I have, which works if the Named range exists,
however causes a break and run time error 1004 if the named range does not
exist.

If ActiveWorkbook.Names("Renewal_Report") Is Nothing Then
Exit Sub
Else
ActiveWorkbook.Names("Renewal_Report").Delete
Selection.AutoFilter

End If

Have I used the correct syntax?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Check if named range exists!

how about something like this

Sub test()
Dim nm As Name

For Each nm In ThisWorkbook.Names
If nm.Name = "Renewal_Report" Then
nm.Delete
Else
Exit Sub
End If
Next
End Sub

--


Gary


"steve_doc" wrote in message
...
Hi all

trying to find a solution to the following small problem. I need to check to
see if a named range exists, if it does I then need to delete it, if it
doesnt I need to exit sub
The following code is what I have, which works if the Named range exists,
however causes a break and run time error 1004 if the named range does not
exist.

If ActiveWorkbook.Names("Renewal_Report") Is Nothing Then
Exit Sub
Else
ActiveWorkbook.Names("Renewal_Report").Delete
Selection.AutoFilter

End If

Have I used the correct syntax?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Check if named range exists!

dim myName as Name
set myName = nothing
on error resume next
set myName = ActiveWorkbook.Names("Renewal_Report")
on error goto 0

if myname is nothing then
exit sub
end if

myname.delete

'etc


steve_doc wrote:

Hi all

trying to find a solution to the following small problem. I need to check to
see if a named range exists, if it does I then need to delete it, if it
doesnt I need to exit sub
The following code is what I have, which works if the Named range exists,
however causes a break and run time error 1004 if the named range does not
exist.

If ActiveWorkbook.Names("Renewal_Report") Is Nothing Then
Exit Sub
Else
ActiveWorkbook.Names("Renewal_Report").Delete
Selection.AutoFilter

End If

Have I used the correct syntax?


--

Dave Peterson
Reply
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
Determining if a named range exists a Excel Programming 2 January 5th 06 01:39 PM
Validate Named Range Exists John Jost Excel Programming 5 December 5th 05 08:17 PM
Check if a number exists in a range? gkaste Excel Discussion (Misc queries) 2 July 13th 05 08:00 PM
how to tell if a named range exists Gixxer_J_97[_2_] Excel Programming 2 June 1st 05 07:38 PM
easy way to test if a Named Range exists Andrew Bauer Excel Programming 4 July 10th 03 07:32 PM


All times are GMT +1. The time now is 11:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"