Is cell value the name used as Named range name

julhs

Active Member
Joined
Dec 3, 2018
Messages
476
Office Version
  1. 2010
Platform
  1. Windows
This is not about testing for if NamedRange exists, because that will have been established.
But I want to compare a cell value against the "Name" used for the NamedRange
So the existing NamedRange is set to this
Rich (BB code):
Name: Name1
Scope: Workbook
RefersTo: Sheet1!$A$6:$C$30
Cell and value to compare is,
Rich (BB code):
G6
Cell value = Name2
I want a way to test that the value of G6 is infact the "Name:" used for the Named range
Because as it stands at moment a Named range can exist but with the wrong name if value in G6 is changed
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I'm not sure I understand your question. You say we needn't check if that range name exists. But how can we decide if the content of cell G6 is right or wrong?
 
Upvote 0
Thanks for response.
Not sure this will help, may well make things worse.
I’m sort of trying to use a reversed logic.
If a range name exists I want to validate that the content of cell G6 is infact the "NAME" used for the existing NamedRange
So say G6 ="Your name" and the "Name: " used in the actual NamedRange is = "Name1"
I’m trying to evaluate if the the 2 are different.
I comes down to pulling the "Name:" used for the existing Named Range and compare it to value in G6
 
Upvote 0
Checking the value of the cell is as easy as this:
VBA Code:
If Range("G6").Value <> "Name1" Then
    'Do something, the content of G6 is different from "Name1"
End If
But I doubt if that is what you are after?
 
Upvote 0
I had tried something like that and tried it agiain.
Unfortunately with the same negative outcome.
I’ll to have further thoughts on this, will come back to you.
 
Upvote 0
Note that in my quick example I haven't added the worksheet, nor the workbook to qualify which workbook and worksheet cell G6 is on, might be important.
 
Upvote 0
Note that in my quick example I haven't added the worksheet, nor the workbook to qualify which workbook and worksheet cell G6 is on, might be important.
Not a problem; that was all done in the main code.

I’ve been beavering away with Google searches and testing, have now come to conclusion that I’ve gone down entirely the wrong route on this!
I believe I should be looking directly at the Name Manager for ranges that “Refers To:” the same range, but has a different “NAME:” applied’
but I haven’t pursued this.
An alternative possibility is to put all the Named Ranges on a separate sheet, which I’ve done using this;
Does range name exist (VBA)? - OzGrid Free Excel/VBA Help Forum
and then check for duplicate Range Definitions (not the “Name:”), which I’m currently working on.
This has turning out to be far more complicated than I first thought, as per usual!
I appreciate your help and any further thoughts you may have.
Julhs
 
Upvote 0
Are you trying to check of two Named Ranges have some of the same cells?
 
Upvote 0
Not quite.
Two Named Ranges referring to EXACT same “Refers To:” range.
Have tried Intersect ActiveCell but it picks up ALL Named range that the ActiveCell is in, so that wasn’t any help
 
Upvote 0
Try this.
VBA Code:
Option Explicit
Option Base 1

Sub compareRangeName()
Dim wb As Workbook, i As Integer, rng() As String, nm() As String, x As Integer
Set wb = Workbooks("Book1") 'Change to your Workbook name.
ReDim rng(wb.Names.Count): ReDim nm(wb.Names.Count)
For i = 1 To UBound(rng)
    rng(i) = wb.Names(i)
    nm(i) = wb.Names(i).Name
Next i
For i = 1 To UBound(rng)
    For x = i + 1 To UBound(rng)
        If rng(i) = rng(x) Then
            MsgBox "Two Names have the same area. " & nm(i) & " and " & nm(x) & "." _
            , vbOKOnly + vbInformation _
                , "Results"
        End If
    Next x
    x = 1
Next i
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top