Checking if a cell has a range name

  • Thread starter James Price at Premier
  • Start date
J

James Price at Premier

I have a worksheet which has a number of Range names. Each named range
relates to one cell only. There will be no instances of more than one range
name in a cell. Can I use VBA to check if the Active Cell has a range name
in it.

Many thanks

James
 
G

Gary''s Student

Try:

Sub WhatsInAName()
On Error GoTo noname
n = ActiveCell.Name
MsgBox ("cell has a name")
Exit Sub
noname:
MsgBox ("cell has no name")
End Sub
 
M

Mike H

Hi,

Try this. You don't need the message boxes, they're to illustrate it works

On Error Resume Next
dummy = ActiveCell.Name.Name
If Len(dummy) = 0 Then
MsgBox "activecell is not in named range"
Else
MsgBox ActiveCell.Name.Name
End If

Mike
 

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