Name Range across multiple (200+) sheets

AndreaBG

New Member
Joined
Mar 15, 2020
Messages
9
Office Version
  1. 2019
Platform
  1. Windows
Hi, I have an excel workbook with 200+sheets of data tables. I need to create a named range for each table.

That is for each table, I go in and highlight a range - say A22:S50 and then name it Table1, Table2 in the name box or I can do this for name manager. Is there a way to automate this process, rather than having to do this for 200 or so tables - can I just somehow set this up so that the name box at top shows the lists of tables going down and each one has A22:S50 as the range it refers to.
 
A little bit of rearranging. I think I have it now.

VBA Code:
Option Explicit

Sub RangeName()
    Dim ws As Worksheet
    Dim rng As Range, x As Long, i As Long
    x = ThisWorkbook.Worksheets.Count
    Dim RangeName As String
    RangeName = "Table"
    x = 1
    For Each ws In Worksheets
        Set rng = ws.Range("A22:S50")
        ws.Names.Add Name:=RangeName & x, RefersTo:=rng
        x = x + 1
    Next ws
End Sub

Capture.JPG
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Thank you. There is one last thing - the scope needs to be the workbook - right now it is that individual sheet. How do you change the scope on all of them to be the workbook.
 
Upvote 0
I don't understand your request. Please provide an example of what you mean.
 
Upvote 0
Try this

VBA Code:
Sub Macro1()
  Dim sh As Worksheet
  For Each sh In Sheets
    ActiveWorkbook.Names.Add "Table" & sh.Index, "=" & sh.Name & "!" & Range("A22:S50").Address
  Next
End Sub
 
Upvote 0
@alansidman, when I run your code, scope is each individual worksheet (3.16 snapshot below) for that worksheet so I can only apply that name range within that worksheet.
I want the scope to be the workbook for each name range so I can apply that name range anywhere.
See example where scope is the workbook for all (see 3.15 snapshot below).

@Dante Amor, The Sub Macro works in that scope is the workbook - however, the table names are not appearing in the name box on top.
 

Attachments

  • 2020-03-15 (3).png
    2020-03-15 (3).png
    246.5 KB · Views: 7
  • 2020-03-16 (2).png
    2020-03-16 (2).png
    101.5 KB · Views: 7
Upvote 0
The Sub Macro works in that scope is the workbook - however, the table names are not appearing in the name box on top.

After running the macro, I see all the names created in the name box:

1584380202177.png


You could do the test in a new book with a couple of sheets.

VBA Code:
Sub Macro1()
  Dim sh As Worksheet
  For Each sh In Sheets
    ActiveWorkbook.Names.Add "Table" & sh.Index, "=" & sh.Name & "!$A$22:$S$50"
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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