I have tried to delete name range in Sheet2 using method 1 and method 2 as below but not workable. One of the name range contains underscore. Error message for both method:
Method 1: Run time error 1004. The syntax of the name is incorrect
Method 2: Run time error 1004. Application-defined or object-defined error
Method 1
Method 2
Method 1: Run time error 1004. The syntax of the name is incorrect
Method 2: Run time error 1004. Application-defined or object-defined error
Method 1
VBA Code:
Sub DeleteNamedRanges()
Dim MyName As Name
For Each MyName In Names
ActiveWorkbook.Names(MyName.Name).Delete
Next
Method 2
VBA Code:
Sub Delete_My_Named_Ranges()
Dim n As Name
Dim Sht As String
' Put in name of sheet where the range is located
Sht = "Sheet2"
For Each n In ActiveWorkbook.Names
If n.RefersToRange.Worksheet.Name = Sht Then
n.Delete
End If
Next n
End Sub