Deleting array with named ranges

PShingadia

New Member
Joined
Aug 5, 2015
Messages
47
Hi All:

Been struggling with this all day and would be grateful for any help. I'm trying to use VBA to delete an array of named ranges but keep getting a Run time error '424' object required when I run the following. It's not the complete code but just the part that should undertake the deletions.

Sub DeleteNames

Dim all_names, n As Name

all_names = Array("INFO_YESNO", "LIST_Cost_Types", "LIST_Cost_Types_Excl_Sal", "LIST_Evaluation_Volumes", "LIST_Locations", "LIST_LOTS", "LIST_MarkUp", "LIST_Milestones")


'Delete range names
For Each n In all_names
Names (n).Delete
Next

End Sub


It stops at line For Each n In all_names
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
What about something like this instead.

VBA Code:
Sub DeleteNames()
    Dim n As name
    Dim WS As Worksheet

    'Delete range names
    'Workbook level names
    For Each n In Names
        Select Case n.name
        Case "INFO_YESNO", "LIST_Cost_Types", "LIST_Cost_Types_Excl_Sal", "LIST_Evaluation_Volumes", "LIST_Locations", "LIST_LOTS", "LIST_MarkUp", "LIST_Milestones"
            n.Delete
        End Select
    Next n

    'Delete range names
    'Worksheet level names
    For Each WS In Worksheets
        For Each n In WS.Names
            Select Case Split(n.name, "!")(1)
            Case "INFO_YESNO", "LIST_Cost_Types", "LIST_Cost_Types_Excl_Sal", "LIST_Evaluation_Volumes", "LIST_Locations", "LIST_LOTS", "LIST_MarkUp", "LIST_Milestones"
                n.Delete
            End Select
        Next n
    Next WS
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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