• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Delete defined names Scoped to Workbook[external]

nagovind

Member
Dear All,

Kindly advise the code that will delete the named ranges that are external to the workbook
Thank you


upload_2018-4-30_17-18-59.png
 
You are looking at wrong property. Scope is context in which Named Range can be referred to (i.e. Worksheet scope named range only works when referenced in specific sheet etc.).

What you want to do is check Refers to: string and check for specific character.

Ex: Since external workbook name is always bounded by "[]".
Code:
Sub Demo()
Dim wName As Name

For Each wName In ThisWorkbook.Names
    If InStr(wName.RefersTo, "[") Then
        wName.Delete
    End If
Next
End Sub
 
Dear Chihiro,
Thank you very much for your reply.
The code is working well and deleted the external reference but few external references as shown below is left undeleted
Kindly advise

upload_2018-5-1_8-59-7.png
 
Those are not standard named range, but generated by setting print properties I believe. Try checking for namedrange.name and if it starts with "Print_" or some other condition, delete it.

If you need further help, upload sample workbook so I can run tests on it.
 
Dear Chihiro,
Thank you very much for your reply.
I have attached a file wherein few named ranges are still left that is referring to external workbook even after running the code
Please help to resolve the same
Thank you
 

Attachments

  • Defined Name external ref delete.xls
    69 KB · Views: 1
Something is very odd about those "Print_..." named ranges.

1. Scope for Print named ranges should never be "workbook" as they are always "Worksheet" level named ranges.
2. No code is able to delete these named range (outside of using .SendKeys). Likely due to scope being out of scope.
3. Odd thing is, while code is unable to delete, there isn't any error thrown either.

You'll need to manually delete these.
 
Back
Top