×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Workbook vs Worksheet names collection problem

Workbook vs Worksheet names collection problem

Workbook vs Worksheet names collection problem

(OP)
I am trying to delete named ranges in my VBA routine.  I use sheet specific name, however, Excel also adds the name to the non-sheet specific.  For example, ActiveWorkbook.Names("test").RefersTo is different than Activesheet.Names("test").RefersTo

I want to delete the workbook level name w/o deleting the worksheet level one.  I can do it when I use the regular excel menu ..  Insert, Names, Define and then select the name and hit delete (while on a sheet that does not have a sheet specific name) but I cannot do it in VBA.  It always deletes the sheet level name first.

Any help would be appreciated, Thanks

RE: Workbook vs Worksheet names collection problem

I had never realized that Excel is so sloppy in managing this. You are right, if you have the same name defined on multiple sheets, you can only get to one of them. The workaround might be to loop through the names collection and selecting the name by the range it refers to:

Dim n As Name
    For Each n In Names
'        Debug.Print n.Name, n.RefersTo
        If n.RefersTo = "=Sheet1!$I$10" Then
            Debug.Print n.Index
'            n.Delete
        End If
    Next n


Good luck!

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources