2 Named Ranges - Same Name - Delete Only 1

SimonGeoghegan

Board Regular
Joined
Nov 5, 2013
Messages
68
Hi All,

I have inadvertently, through another piece of code, got a number of files that have 2 named ranges with the same name. I'd like to delete just one of these but not sure how i'd write the code to ensure I was deleting the correct one (the bottom of the 2 below):

Name | Value | Refers To | Scope
CashCompliance1 | 0% | = 'Cash Management'!$C$69 | Cash Management
CashCompliance1 | {…} | ='\\BMIFILES\Teams\Users\sgeoghegan\Desktop\Self Assessments WIP\[Self Assessment Hospital Template.xlsm]Cash Management'!$C$69| Workbook


Apologies for the lack of image.

I have all the loop code etc. to wrap around, and I've seen code for deleting ranges - but nothing specific to identify a range based upon on the "Refers To" section.

Any help greatly appreciated.

Thanks,
Simon
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
The following macro will loop through each name within the active workbook, and deletes the first name it comes across where "Refers to" starts with "='\\BMIFILES" . . .

Code:
Sub DeleteName()

    Dim nme As Name
    
    For Each nme In ActiveWorkbook.Names
        If Left(nme.RefersTo, 13) = "='\\BMIFILES\" Then
            nme.Delete
            Exit For
        End If
    Next nme
    
End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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