![]() |
how do i test for the existence of a range name
Hi rrobelen,
You can simply trap the error that may occur if it doesn't exist: Public Function gbDoesNameExist(rwb As Workbook, _ rsName As String) As Boolean On Error Resume Next gbDoesNameExist = Len(rwb.Names(rsName).Name) On Error GoTo 0 End Function -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] rrobelen wrote: I know this must be trivial but I can't find it. How do i test to see that a range name exists? |
how do i test for the existence of a range name
Thanks Marx
I thought there might be a simple test sort of like the iserror class of tests but I guess not. I thought of using this but was looking for the simple one. Thanks i am sure is more bullet proof then mine would have been. Again thanks for the quick response Regards Rus ----- Jake Marx wrote: ---- Hi rrobelen You can simply trap the error that may occur if it doesn't exist Public Function gbDoesNameExist(rwb As Workbook, rsName As String) As Boolea On Error Resume Nex gbDoesNameExist = Len(rwb.Names(rsName).Name On Error GoTo End Functio -- Regards Jake Mar MS MVP - Exce www.longhead.co [please keep replies in the newsgroup - email address unmonitored rrobelen wrote I know this must be trivial but I can't find it. How do i test t see that a range name exists? |
how do i test for the existence of a range name
Hi Russ,
You could use the Evaluate function along with the TypeName function to see if you have a valid range in the active workbook: If TypeName(Evaluate("test")) = "Range" Then MsgBox "Name found" Else MsgBox "Name not found" End If If you're looking on a specific worksheet, you can do this: If TypeName(Workbooks("Book1.xls").Sheets("Sheet1" _ ).Evaluate("test")) = "Range" Then I prefer the On Error method in this case, as it allows more flexibility. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] rrobelen wrote: Thanks Marx, I thought there might be a simple test sort of like the iserror class of tests but I guess not. I thought of using this but was looking for the simple one. Thanks i am sure is more bullet proof then mine would have been. Again thanks for the quick response. Regards, Russ ----- Jake Marx wrote: ----- Hi rrobelen, You can simply trap the error that may occur if it doesn't exist: Public Function gbDoesNameExist(rwb As Workbook, _ rsName As String) As Boolean On Error Resume Next gbDoesNameExist = Len(rwb.Names(rsName).Name) On Error GoTo 0 End Function -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] rrobelen wrote: I know this must be trivial but I can't find it. How do i test to see that a range name exists? |
All times are GMT +1. The time now is 12:59 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com