Solved

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

Posted on 2011-09-03
3
318 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 500 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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

688 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