How to delete multiple defined names in excel 2003

Deadpool

New Member
Joined
Mar 5, 2015
Messages
14
how to delete multiple defined names in excel 2003. I came across this macro to do so but it is giving me a run time error. Not sure what is wrong with it. I used a excel spreadsheet from a friend that had a bunch of named cells and I don't know how to remove all of them. Please help



Sub
DeleteAllNamesWithREFError()

Dim N As Name

If MsgBox("Are you sure?", vbYesNo + vbDefaultButton2, "Confirm macro") = vbNo Then Exit Sub

For Each N In ActiveWorkbook.Names

If InStr(N.Value, "#REF") Then N.Delete

Next N

End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
As it stands, your code only deletes names that contain the error value #REF ! To delete all names, whether or not they include the error value, replace...

Code:
If InStr(N.Value, "[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=REF]#REF[/URL] ") Then N.Delete

with

Code:
N.Delete

Hope this helps!
 
Upvote 0
As it stands, your code only deletes names that contain the error value #REF ! To delete all names, whether or not they include the error value, replace...

Code:
If InStr(N.Value, "[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=REF"]#REF[/URL] ") Then N.Delete

with

Code:
N.Delete

Hope this helps!

Thank you for the help. So I tried this and it went to the debug. Is this correct?

Sub
DeleteAllNamesWithREFError()

Dim N As Name

If MsgBox("Are you sure?", vbYesNo + vbDefaultButton2, "Confirm macro") = vbNo Then Exit Sub

For Each N In ActiveWorkbook.Names

Then N.Delete

Next N

End Sub
 
Upvote 0
No, it should be this way...

Code:
Sub DeleteAllNames()

    Dim N As Name
    
    If MsgBox("Are you sure?", vbYesNo + vbDefaultButton2, "Confirm macro") = vbNo Then Exit Sub
    
    For Each N In ActiveWorkbook.Names
    
        N.Delete
    
    Next N


End Sub

You'll notice that I took the liberty to change the name of the macro to DeleteAllNames, since you in fact want to delete all names. :)
 
Upvote 0
No, it should be this way...

Code:
Sub DeleteAllNames()

    Dim N As Name
    
    If MsgBox("Are you sure?", vbYesNo + vbDefaultButton2, "Confirm macro") = vbNo Then Exit Sub
    
    For Each N In ActiveWorkbook.Names
    
        N.Delete
    
    Next N


End Sub

You'll notice that I took the liberty to change the name of the macro to DeleteAllNames, since you in fact want to delete all names. :)


Thank you so much that worked have a great day.
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,765
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top