VBA To Convert Named Ranges: Workbook To Worksheet Scope

What This VBA Code Does

I had a project today that required me to change the scope of all my Worbook-level named ranges to Worksheet-level named ranges. There were hundreds of named ranges and I didn't want to go through the arduous process of recreating them so I created this little VBA subroutine to create Worksheet Scoped versions of any Workbook Scoped named range with the phrase "Table" in the name.

Sub CreateWorksheetScopedNameRanges()
'PURPOSE: Create Worksheet Scoped versions of Workbook Scoped Named Ranges
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault

Dim nm As Name
Dim rng As Range
Dim FilterPhrase As String

'Filter Named Ranges that contain specific phrase
  FilterPhrase = "Table"

'Loop Through each named Range
  For Each nm In ActiveWorkbook.Names
  
    'Is Name scoped at the Workbook level?
      If TypeOf nm.Parent Is Workbook Then
        
        'Does Name meet Filter Phrase Requirement? If so, recreate named range with Worksheet Scope
          If InStr(1, nm.Name, FilterPhrase) > 0 Then
            Set rng = Range(nm.RefersTo)
            rng.Parent.Names.Add Name:=nm.Name, RefersToR1C1:="=" & rng.Address(ReferenceStyle:=xlR1C1)
          End If
          
      End If
      
  Next nm

End Sub

I then wrote another VBA subroutine to delete all the Workbook Scoped named ranges I had just replicated

Sub DeleteWorkbookScopedNamedRanges()

'PURPOSE: Remove specific Workbook Scoped Named Ranges
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault

Dim nm As Name
Dim rng As Range
Dim FilterPhrase As String

'Filter Named Ranges that contain specific phrase
  FilterPhrase = "Table"

'Loop Through each named Range
  For Each nm In ActiveWorkbook.Names
  
    'Is Name scoped at the Workbook level?
      If TypeOf nm.Parent Is Workbook Then
        
        'Does Name meet Filter Phrase Requirement? If so, delete named range
          If InStr(1, nm.Name, FilterPhrase) > 0 Then nm.Delete
          
      End If
      
  Next nm

End Sub

How Do I Modify This To Fit My Specific Needs?

Chances are this post did not give you the exact answer you were looking for. We all have different situations and it's impossible to account for every particular need one might have. That's why I want to share with you: My Guide to Getting the Solution to your Problems FAST! In this article, I explain the best strategies I have come up with over the years to getting quick answers to complex problems in Excel, PowerPoint, VBA, you name it

I highly recommend that you check this guide out before asking me or anyone else in the comments section to solve your specific problem. I can guarantee 9 times out of 10, one of my strategies will get you the answer(s) you are needing faster than it will take me to get back to you with a possible solution. I try my best to help everyone out, but sometimes I don't have time to fit everyone's questions in (there never seem to be quite enough hours in the day!).

I wish you the best of luck and I hope this tutorial gets you heading in the right direction!

- Chris
Founder, TheSpreadsheetGuru.com