This is a tough one : deleting names, but in a specific range in VBA

MissMJ

New Member
Joined
Jul 29, 2015
Messages
3
Hello,

I am trying to figure out how to delete names of ranges in a specific range, using vba code.

I tried this :

ActiveWorkbook.Worksheets("Sheet1").Range("e6:bx2000").Names.Delete

but it doesn't work. I googled it... got nothing :eek:

Please help
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Welcome to the board. This is a guess, but you try (test on a copy of your file first):
Code:
Sub DeleteNamedRanges()

Dim nm  As Excel.Names
Dim rng As Excel.Range

    Application.ScreenUpdating = False
    
    With Sheets("Sheet1")
        Set rng = .Range("E6:BX2000")
        
        For Each nm In activeworkbooks.Name
            If Intersect(rng, Range(nm.Name)) Then nm.Delete
        Next nm
                
    End With
    
    Set rng = Nothing
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Ignore, found an error in above code. Try:
Code:
Sub DeleteNamedRanges()

Dim nm  As Excel.Name
Dim rng As Excel.Range

    Application.ScreenUpdating = False
    
    With ThisWorkbook.Sheets("Sheet1")
        Set rng = .Range("A6:BX2000")

        For Each nm In ActiveWorkbook.Names
            If Not Intersect(rng, .Range(nm.RefersToRange.Address)) Is Nothing Then
                nm.Delete
            End If
        Next nm
                
    End With
    
    Set rng = Nothing
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
These are good ideas, but the problem is that the name of the range is given with the sheet name attached. I guess I have to use the SPLIT function and then put the name of the sheet in SHEETS().range(nm) ?
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,181
Members
448,871
Latest member
hengshankouniuniu

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