Solved

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

Posted on 2011-09-03
3
298 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
  • 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

821 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