Named Range Macro

Mashtonsmith1

New Member
Joined
May 16, 2020
Messages
30
Office Version
  1. 365
Platform
  1. Windows
Hello,

Help please. I need a macro which will create a named range based on the selected cells in each sheet.

Each sheet is named as a ref number and the cell selection will always start as a year.

So after running the macro it should name the selected cells "REF NO_YEAR". Actually selecting the cells/range will be manual.

My workbook has over 200 tabs so I should end up with around 400 named ranges (for 2022 and 2023)

I wont be able to run this across the entre work book as the loaction of the data I want isn't in a consistent position - I'll need to do it for each sheet using this macro.

Many thanks
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Based on the info provided, perhaps something like this in a standard module:
VBA Code:
Sub AddRange()
Dim rng As Range
Dim nme As Name

Set rng = Application.InputBox("Select Range", Type:=8)
ThisWorkbook.Names.Add Name:="REF_NO_YEAR", RefersTo:=rng

End Sub
That would create a named range at the workbook level (not the sheet) which is what I interpret that you want. It won't check if the named range already exists so it will take on whatever range you select for that name. BTW, AFAIK, named ranges cannot contain spaces so it's not exactly what you posted for the name.
 
Upvote 0

Forum statistics

Threads
1,215,196
Messages
6,123,578
Members
449,108
Latest member
rache47

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