Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default If Range.Name question

Excel XP & Win XP
I want to check if the ActiveCell range name is "Hello". I thought this
little macro would work but it returns a "No". What is the correct way to
make this check? Thanks for your help. Otto
Sub TestName()
If ActiveCell.Name = "Hello" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default If Range.Name question

Hi Otto

You must have Name twice. The first
Name returns the address of the cell, and
the second Name returns the name of
that address (if any).

Sub TestName()
If ActiveCell.Name.Name = "Hello" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub

--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"Otto Moehrbach" skrev i en meddelelse
...
Excel XP & Win XP
I want to check if the ActiveCell range name is "Hello". I thought this
little macro would work but it returns a "No". What is the correct way to
make this check? Thanks for your help. Otto
Sub TestName()
If ActiveCell.Name = "Hello" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default If Range.Name question

Otto,

Try something like the following:

Dim S As String
On Error Resume Next
S = ActiveCell.Name.Name
On Error GoTo 0
If StrComp(S, "Hello", vbTextCompare) = 0 Then
MsgBox "Yes"
Else
MsgBox "No"
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Otto Moehrbach" wrote in message
...
Excel XP & Win XP
I want to check if the ActiveCell range name is "Hello". I

thought this
little macro would work but it returns a "No". What is the

correct way to
make this check? Thanks for your help. Otto
Sub TestName()
If ActiveCell.Name = "Hello" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default If Range.Name question

The Name object's default property is .Value, not .Name:

For instance, in the immediate window:

? ActiveCell.Name
=Sheet1!$A$1

? ActiveCell.Name.Value
=Sheet1!$A$1

?ActiveCell.Name.Name
Hello

So your code could be rewritten:

Sub TestName()
If ActiveCell.Name.Name = "Hello" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub


In article ,
"Otto Moehrbach" wrote:

Excel XP & Win XP
I want to check if the ActiveCell range name is "Hello". I thought this
little macro would work but it returns a "No". What is the correct way to
make this check? Thanks for your help. Otto
Sub TestName()
If ActiveCell.Name = "Hello" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default If Range.Name question

Otto,

Remember Google ??? <vbg

From a John Greene post.....

for a single cell range:
Activecell.Name.Name

for a multiple cell range:
Sub WhereAmI()
Dim n As Name
On Error Resume Next
For Each n In Names
If Intersect(ActiveCell, n.RefersToRange) Is Nothing Then
Else
MsgBox "Active cell is in " & n.Name
Exit Sub
End If
Next n
End Sub

John


"Otto Moehrbach" wrote in message
...
Excel XP & Win XP
I want to check if the ActiveCell range name is "Hello". I thought this
little macro would work but it returns a "No". What is the correct way to
make this check? Thanks for your help. Otto
Sub TestName()
If ActiveCell.Name = "Hello" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default If Range.Name question

Thanks Leo, Chip, J.E. and John. My forehead is getting flat from hitting
it with the palm of my hand. Otto
"Otto Moehrbach" wrote in message
...
Excel XP & Win XP
I want to check if the ActiveCell range name is "Hello". I thought this
little macro would work but it returns a "No". What is the correct way to
make this check? Thanks for your help. Otto
Sub TestName()
If ActiveCell.Name = "Hello" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default If Range.Name question

You're welcome, Otto.
I *told* the other guys, that we shouldn't
give you a hand. Now look :-))

--
Best Regards
LeoH


"Otto Moehrbach" skrev i en meddelelse
...
Thanks Leo, Chip, J.E. and John. My forehead is getting flat from hitting
it with the palm of my hand. Otto



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default If Range.Name question

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")
......
.....

Regards, Andy


-----Original Message-----
Excel XP & Win XP
I want to check if the ActiveCell range name is "Hello".

I thought this
little macro would work but it returns a "No". What is

the correct way to
make this check? Thanks for your help. Otto
Sub TestName()
If ActiveCell.Name = "Hello" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub


.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default 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")
.....
....

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Range question Jock Excel Worksheet Functions 3 March 19th 08 04:36 PM
Range Question Peter[_8_] Excel Discussion (Misc queries) 3 December 11th 07 02:37 AM
Range Question N.F[_2_] Excel Discussion (Misc queries) 5 July 28th 07 01:05 AM
Range question in '97 Adam Kroger Excel Discussion (Misc queries) 10 December 12th 05 03:44 AM
Range.Formula and Range question using Excel Automation [email protected] Excel Programming 0 September 19th 03 04:53 AM


All times are GMT +1. The time now is 12:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"