?
Solved

Check for the existence of a named range on a specific worksheet of  the current  workbook

Posted on 2011-09-03
3
Medium Priority
?
321 Views
Last Modified: 2012-05-12
Dear Experts:

I would  like to check ...

... for the existence of a workbook level name (MyDataRange) in the current workbook.
... if Found the macro will check on which worksheet the workbook level name exists:

(1) if the named range is NOT located on the worksheet named 'DATA',
... a msgbox will tell the user the name of the worksheet including the cell references and the ... the macro will afterwards DELETE the workbook level name (MyDataRange). Afterwards the macro is to exit.
(2) If the named range IS located on the worksheet named 'DATA' a msgbox will say so including specifying the cell references of the named range

... if the workbook level name 'MyDataRange' does NOT EXIST at all, a msgbox  is to say so and the macro is to exit.

Help is much appreciated. Thank you very much for your professional help in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 2000 total points
ID: 36478149
Here is a macro that checks for your named range:

Sub RangeChecker()
Dim rg As Range
Dim ws As Worksheet
Dim sName As String
sName = "MyDataRange"
On Error Resume Next
Set rg = ActiveWorkbook.Names(sName).RefersToRange
On Error GoTo 0
If rg Is Nothing Then
    MsgBox sName & " was not found"
ElseIf UCase(rg.Worksheet.Name) = "DATA" Then
    MsgBox sName & " exists on worksheet DATA at " & rg.Address(False, False)
    'Do more stuff here
Else
    MsgBox sName & " found instead on worksheet " & rg.Worksheet.Name & " at " & rg.Address(False, False)
End If
End Sub

Open in new window


Brad
0
 

Author Comment

by:AndreasHermle
ID: 36478978
Hi Brad:  

great job. Concise coding. That's exactly the way I wanted it. Thank you very much for your professional help. I really appreciate it.

Regards, Andreas
0
 

Author Closing Comment

by:AndreasHermle
ID: 36478980
Great job, great forum.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question