ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete All Names - Even Invalid "#REF" Names (https://www.excelbanter.com/excel-programming/386721-delete-all-names-even-invalid-ref-names.html)

Brian B.

Delete All Names - Even Invalid "#REF" Names
 
FYI: The following code will delete all names in a workbook, including
those with a "#REF" error:

Sub Delete_Names()

Dim NameX As Name
On Error GoTo Nxt
For Each NameX In Names
ActiveWorkbook.Names(NameX.Name).Delete
Nxt:
Next NameX

End Sub

Adding the "On Error GoTo" will allow the code to also delete invalid
names too. I couldn't find this anywhere so I though I'd post it ...

-Brian


Peter T

Delete All Names - Even Invalid "#REF" Names
 
To delete all names simply -

Dim nm as Name
for each nm in Activeworkbook.Names
nm.delete
Next

I can't think of anything that would raise an error doing this and require
some sort of error handler.

Regards,
Peter T


"Brian B." wrote in message
ups.com...
FYI: The following code will delete all names in a workbook, including
those with a "#REF" error:

Sub Delete_Names()

Dim NameX As Name
On Error GoTo Nxt
For Each NameX In Names
ActiveWorkbook.Names(NameX.Name).Delete
Nxt:
Next NameX

End Sub

Adding the "On Error GoTo" will allow the code to also delete invalid
names too. I couldn't find this anywhere so I though I'd post it ...

-Brian





All times are GMT +1. The time now is 01:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com