We’d like to remind Forumites to please avoid political debate on the Forum.
This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
The Forum now has a brand new text editor, adding a bunch of handy features to use when creating posts. Read more in our how-to guide
Deleting Multiple Range names in Excel
Gambler
Posts: 3,405 Forumite
in Techie Stuff
I've been searching the net trying to find a macro that will delete all the old range names in my workbook. All the range names start "=#REF!" as they are linking to files that no longer exists. I cam accross the following but it doesn't work. Any help appreciated. Thanks
Sub DeletePhantomRangeNames()
For Each nm In ActiveWorkbook.Names
If nm.RefersTo Like "*REF!*" Then
nm.Delete
End If
Next nm
End Sub
P.S. I've used a macro to do this before but I can't for the life of me find the file
Sub DeletePhantomRangeNames()
For Each nm In ActiveWorkbook.Names
If nm.RefersTo Like "*REF!*" Then
nm.Delete
End If
Next nm
End Sub
P.S. I've used a macro to do this before but I can't for the life of me find the file
0
Comments
-
' This procedure deletes every named range in which the RefersTo
' argument contains #REF!, where #REF! begins at the second character
' and ends at the fifth.
Sub Delete_Every_Named_Range_With_A_Reference_Error()
Dim nm As Object
Dim mystr As String
' Loops through each name in the active workbook.
For Each nm In ActiveWorkbook.Names
' Check for #REF! in the defined name reference.
If InStr(1, nm.RefersTo, "#REF!") Then
' Delete the defined name if it is a match.
nm.Delete
End If
Next
End Sub2026 Mortgage-Free Wannabes #24 £8797.50/£20000 OP0 -
scottishlass wrote: »' This procedure deletes every named range in which the RefersTo
' argument contains #REF!, where #REF! begins at the second character
' and ends at the fifth.
Sub Delete_Every_Named_Range_With_A_Reference_Error()
Dim nm As Object
Dim mystr As String
' Loops through each name in the active workbook.
For Each nm In ActiveWorkbook.Names
' Check for #REF! in the defined name reference.
If InStr(1, nm.RefersTo, "#REF!") Then
' Delete the defined name if it is a match.
nm.Delete
End If
Next
End Sub
Thanks. Have tried but getting the same as the earlier macro.Run-time error '1004':
That name is not valid0 -
Ummm....
Do you have any global Workbook name objects with the same name as the local Worksheet name object you are trying to delete?2026 Mortgage-Free Wannabes #24 £8797.50/£20000 OP0 -
scottishlass wrote: »Ummm....
Do you have any global Workbook name objects with the same name as the local Worksheet name object you are trying to delete?
Ummm...........no idea
0 -
Ok: whats your file saved as and what are the names of your worksheets?
2026 Mortgage-Free Wannabes #24 £8797.50/£20000 OP0
This discussion has been closed.
Confirm your email address to Create Threads and Reply
Categories
- All Categories
- 353.8K Banking & Borrowing
- 254.2K Reduce Debt & Boost Income
- 455.2K Spending & Discounts
- 246.9K Work, Benefits & Business
- 603.4K Mortgages, Homes & Bills
- 178.2K Life & Family
- 260.9K Travel & Transport
- 1.5M Hobbies & Leisure
- 16K Discuss & Feedback
- 37.7K Read-Only Boards
