Checking for named ranges in a workbook

L

loopoo

Hello!

Can anyone help me with the following problem:

I have some ranges in my workbook, and I want to check if the content
of a cell is the name of a range.

For example:

I have :
range1
range2
range3
range4
range5

I want to see if ActiveCell.Offset(0,-2).Value is one of the named
ranges in the workbook.

How can I make that check???


Thanks in advance,
Chris
 
N

Norman Jones

Hi Chris,

Try something like:

'==========>>
Sub aTest()
Dim rng As Range
Dim nme As Name

Set rng = ActiveCell '<<==== CHANGE

For Each nme In ActiveWorkbook.Names
If UCase(nme.Name) = UCase(rng.Offset(0, -2).Value) Then
MsgBox "valid name"
Exit Sub
End If
Next nme

MsgBox "No corresponding name found"

End Sub
'<<==========
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top