Delete ALL named ranges

ExcelRoy

Well-known Member
Joined
Oct 2, 2006
Messages
2,540
Office Version
  1. 365
Platform
  1. Windows
Hi,

would there be a code to delete all the named ranges in a workbook, but keep the cell referenced formulas so the calculations remain intact

Thanks
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
This will do the trick:

Code:
Sub Test()

For Each nam In ActiveWorkbook.Names

    a = nam.Name
    b = Replace(nam.RefersToRange.Address, "$", "")
    
    For Each ws In ActiveWorkbook.Worksheets
    
        Cells.Replace What:="" & a & "", Replacement:="" & b & "", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

    Next ws

    nam.Delete

Next nam

End Sub

Be careful, when a range is called 'then' it will also replace all words 'then' in typed text.
 
Last edited:
Upvote 0
Very nice method, thanks for that.

My followup question regards your Replace() command to remove the $ symbols from the addresss. Why did you choose do that? Since most named ranges are "absolute", converting to flat addresses I would expect to be converted to absolute range addresses? No?
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

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