Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Determining if a named range exists | Excel Programming | |||
Validate Named Range Exists | Excel Programming | |||
Check if a number exists in a range? | Excel Discussion (Misc queries) | |||
how to tell if a named range exists | Excel Programming | |||
easy way to test if a Named Range exists | Excel Programming |