Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

How to know if cell has name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick S. - 14 Mar 2008 20:45 GMT
How can I test a cell for a Name, "activecell.name".
In my code below, it will generate an error if a cell is clicked that has no
".Name".
(Option Explicit assumed)

'======
Sub x()
'Begin Registry setting
'Notes:
'100% active on all cells clicked
   sSpecLastWs = ActiveSheet.Name
   SaveSetting appname:="ADM_Spec_Index", section:="WorkSheetNames", _
               Key:="sSpecLastWs", setting:=sSpecLastWs
   sSpecLastCell = ActiveCell.Name 'FAILS HERE
   SaveSetting appname:="ADM_Spec_Index", section:="WorkSheetNames", _
               Key:="sSpecLastCell", setting:=sSpecLastCell
   'End Registry setting
End Sub
'======
Signature

Regards

VBA.Newb.Confused
XP Pro
Office 2007

Gary''s Student - 14 Mar 2008 21:00 GMT
Select a cell and run:

Sub nameit()
For Each n In ActiveWorkbook.Names
   Set r = Range(n)
   If Intersect(ActiveCell, r) Is Nothing Then
   Else
       MsgBox ("activecell " & ActiveCell.Address & " is part of " & n.Name)
       Exit Sub
   End If
Next
MsgBox ("activecell " & ActiveCell.Address & " is Nameless")
End Sub

It is important to remember that a cell can have its own name or be part of
a range with a name or be a part of several ranges with different names.
Signature

Gary''s Student - gsnu200773

> How can I test a cell for a Name, "activecell.name".
> In my code below, it will generate an error if a cell is clicked that has no
[quoted text clipped - 15 lines]
> End Sub
> '======
Rick S. - 14 Mar 2008 21:03 GMT
Gary, Thanks!
I definately did not know this:
"It is important to remember that a cell can have its own name or be part of
a range with a name or be a part of several ranges with different names."
Signature

Regards

VBA.Newb.Confused
XP Pro
Office 2007

> Select a cell and run:
>
[quoted text clipped - 32 lines]
> > End Sub
> > '======
Rick S. - 14 Mar 2008 21:07 GMT
With Gary's aid:
The macro appears to function like I think it should. ;)
'======
Sub x()    'for all other links
   Dim r As Range
   'Begin Registry setting
   sSpecLastWs = ActiveSheet.Name
   SaveSetting appname:="ADM_Spec_Index", section:="WorkSheetNames", _
               Key:="sSpecLastWs", setting:=sSpecLastWs
   Set r = Range(ActiveCell.Address)
   If Intersect(ActiveCell, r) Is Nothing Then
   Else
       sSpecLastCell = ActiveCell.Name
       SaveSetting appname:="ADM_Spec_Index", section:="WorkSheetNames", _
                   Key:="sSpecLastCell", setting:=sSpecLastCell
       'End Registry setting
   End If
End Sub
'======
Signature

Regards

VBA.Newb.Confused
XP Pro
Office 2007

> Select a cell and run:
>
[quoted text clipped - 32 lines]
> > End Sub
> > '======
Peter T - 14 Mar 2008 23:12 GMT
Don't see how that helps at all. Try this

Dim nm As Name

On Error Resume Next
Set nm = Nothing ' if necessary reset
Set nm = ActiveCell.Name
On Error GoTo 0

If nm Is Nothing Then
' not named, maybe name it
Debug.Print "not named"
Else
Debug.Print nm.Name, nm.RefersTo
End If

Regards,
Peter T

> With Gary's aid:
> The macro appears to function like I think it should. ;)
[quoted text clipped - 52 lines]
> > > End Sub
> > > '======
Peter T - 14 Mar 2008 23:17 GMT
What I should have done of course, had I seen it, was refer you to Dave's
earlier post, rather than repeat what he had already demonstrated !

Regards,
Peter T

> Don't see how that helps at all. Try this
>
[quoted text clipped - 77 lines]
> > > > End Sub
> > > > '======
Dave Peterson - 14 Mar 2008 23:28 GMT
I think it happens to all of us.  Well, I know it happens to me!

> What I should have done of course, had I seen it, was refer you to Dave's
> earlier post, rather than repeat what he had already demonstrated !
[quoted text clipped - 103 lines]
> > > > > XP Pro
> > > > > Office 2007

Signature

Dave Peterson

Dave Peterson - 14 Mar 2008 21:42 GMT
If you really want to check to see if the activecell has its own name:

   Dim myName As Name

   Set myName = Nothing
   On Error Resume Next
   Set myName = ActiveCell.Name
   On Error GoTo 0
   
   If myName Is Nothing Then
       MsgBox "no name"
   Else
       MsgBox ActiveCell.Address(0, 0) & vbLf & myName.Name
   End If

> How can I test a cell for a Name, "activecell.name".
> In my code below, it will generate an error if a cell is clicked that has no
[quoted text clipped - 21 lines]
> XP Pro
> Office 2007

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.