If Range.Name question
Potential pitfall there, too: if ws isn't the activesheet, you may
get a false positive (i.e., cell named "Hello" is Sheet1!A1,
activecell is Sheet2!A1, then
Sheets("Sheet1").Range("Hello").Address = ActiveCell.Address
is True.
Another way:
Dim nmA As Name
Dim sMsg As String
sMsg = "No"
On Error Resume Next
Set nmA = ActiveCell.Name
On Error GoTo 0
If Not nmA Is Nothing Then _
If nmA.Name = "Hello" Then _
sMsg = "Yes"
MsgBox sMsg
In article ,
"Andy Keen" wrote:
This is an interesting one! The name property of a range
(or cell) is not the string it is named, but another name
object, so ActiveCell.Name.Name returns "Hello". However,
if the cell is not named at all, you will just get an
error. Not sure how you tell if a cell has a name attached
or not.
As long as you know the "Hello" cell exists the best way
is just to check if it is the ActiveCell - that is:
If ws.Range("Hello").Address = ActiveCell.Address Then
MsgBox ("YES")
.....
....
|