I have a macro that needs to delete all named ranges in my Workbook. Every time I run it, I get a 1004 Run-time error unless I include an error handler. When I include an error handler, it works and actually deletes all of the named ranges. Why does that happen? For context, the code I am showing below is an excerpt of a sub.
This works and does not produce an error:
Dim nm As Name
Dim wb3 As Workbook
Set wb3 = ActiveWorkbook
For Each nm In wb3.Names
On Error GoTo Skip
nm.Delete
Skip:
On Error GoTo 0
Next
This gives the 1004 error:
Dim nm As Name
Dim wb3 As Workbook
Set wb3 = ActiveWorkbook
For Each nm In wb3.Names
nm.Delete
Next
The error occurs at nm.Delete
nm.Delete
:Debug.Print nm.Name
– AAA.Name
for example? – BigBen