Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Copying Named Ranges.

Copying Named Ranges

by Allen Wyatt
(last updated November 7, 2015)


Graeme has a workbook that has a large number (120+) named ranges defined within it. He would like to copy the range names and definitions to a different workbook. Thus, after copying, the range named MyRange1 which refers to the range C7:H22 in the original workbook will exist in the target workbook and refer to the same range, in the target workbook. Nothing else should be copied from the original workbook to the target—just the range names and definitions.

The easiest way to do this is with a macro that steps through each of your defined names and copies the name definition to the target workbook. Here's an example:

Sub CopyNames()
    Dim Source As Workbook
    Dim Target As Workbook
    Dim n As Name

    Set Source = ActiveWorkbook
    Set Target = Workbooks("Book2.xlsx")

    For Each n In Source.Names
        Target.Names.Add Name:=n.Name, RefersTo:=n.Value
End Sub

Note that the majority of the work in the macro is done in the For Each loop that steps through all the defined names. It creates the name in the target workbook and gives it the same assignment as it had in the source workbook (contained in the Value property).

It should be noted that, by default, named ranges include the name of the worksheet in the Value property. If the source workbook has a named range that refers to, say, Sheet4 and there is no Sheet4 in the target workbook, then the addition of the name fails. The macro doesn't generate an error; it simply doesn't create the new named range. The solution is to either (a) make sure that the target workbook contains the same sheet names as the source workbook or (b) modify the macro so that it recognizes that there are missing sheets and takes whatever action is appropriate.

If you prefer to not create a macro, then the easiest method may be to copy your worksheets from the source workbook to a target workbook. Excel generally copies the named ranges along with the worksheets. The only time this would not be a satisfactory approach is if the target workbook already has worksheets with the same names as those worksheets you might want to copy. In that case, you'd be best to use the macro approach.


If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8811) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Copying Named Ranges.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Columns in a Text Box

Want to divide a text box into columns? Word doesn't allow you to do this, but there are ways to work around the limitation.

Discover More

Changing Default Search Settings

Excel provides some great tools for finding information in a worksheet or a workbook. Changing the default settings used ...

Discover More

Segregating Numbers According to Their Sign

Remember your number line from your early years in school? Some numbers can be below zero (negative numbers) and others ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Replacing Some Formulas with the Formula Results

Macros are often used to process the data stored in a worksheet. Some of these processing needs can be pretty specific to ...

Discover More

Creating a Function Inventory for a Workbook

Your worksheets are very often made up of formulas and these formulas are made up of functions. If you ever want to ...

Discover More

Updating a Web Query Based on a Schedule

Want to make sure that a web query is only executed during certain hours? It may be as easy as scheduling when to turn ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two less than 8?

2021-04-29 14:58:19

J. Woolley

You might be interested in My Excel Toolbox's freely available array function
ListNames([Scope], [SkipHidden], [SkipHeader]) and macro UnhideNames(). These procedures make it possible to view defined names (named ranges) that are normally hidden (not visible). See

2021-04-28 06:27:41

M. Fra

Hello, I would like to share the version of this macro that I used. I ran into an issue with hidden names in my workbook- these were found by using the Name Manager+ from They looked like _xlfn._xlws.FILTER =#NAME? To skirt this issue arising, I only use the visible names. The second change I made was the RefersTo value. I wanted it to be the name of my source + the reference value, so =[Source.xlsm]$A$1. Therefore I had to remove the "=" from x.Value, and combine it with a string containing the source workbook name. Finally, I run the macro with both workbooks open, and just in case, I made sure that Book2.xlsm had the same number of sheets as the source workbook.

Sub Copy_All_Defined_Names()
' Loop through all of the defined names in the active
' workbook.
String1 = "=[Source.xlsm]"
For Each x In ActiveWorkbook.Names
' Check if name is visible; only use the visible names
If x.Visible = True Then
' Add each defined name from the active workbook to
' the target workbook ("Book2.xls" or "Book2.xlsm").
' "x.Value" refers to the cell references the defined name points to.
String2 = x.Value
Result = Replace(String2, "=", "")

InputText = String1 & Result
Workbooks("Book2.xlsm").Names.Add Name:=x.Name, _
End If
Next x
End Sub

2018-09-08 05:51:09

Willy Vanhaelen

If your Book2.xlsx doesn't contain the sheets with the same name as your source sheet (active sheet), the macro will crash.

2018-09-07 17:22:23


I had the same issue as Cameron Wild. When I click in the line, it looks like it is trying to pull in a function "xlfn.AVERAGEIFS" which comes back with a refers to of "=#NAME?" error which is killing the program. Why is it pulling in Excel Functions instead of just defined names? Does anyone know how to only pull in defined names? Thanks for any help you can give.

2018-06-04 06:25:37

Cameron Wild

Doesn't work in Excel 2016 :(

Says syntax of the name is incorrect - highlights this line:

Target.Names.Add Name:=n.Name, RefersTo:=n.value

2017-02-13 12:04:26

Andrew: The "subscript out of range" error means that you don't have a workbook open that is named Book2.xlsx.


2017-02-13 12:01:30


Failing on the line

Set Target = Workbooks("Book2.xlsx")


Runtime Error '9': Subscript out of range.

Just to validate I was using the right destibnation file, I copied the full posix compliant path to Workbooks(""). I also opened up the target file and use the "immediate window" and ran

? activeworkbook.fullname

and got
Macintosh HD:Users:my_userid:Documents:Oly:OlyJunk.xlsm

and pasted that into the Workbooks() function.. Same result.

What could be the problem? The target has the exact-same named worksheets and data ranges as the source.

2016-05-16 10:23:29


Keeping this page with the macro open, open Excel and the file you are working.
Click the Developer tab
Click Macros. This will open up VBA.
Type "CopyNames" (without the quotes) in the Macro Name box.
Click Create
Highlight and copy the macro in the web page
Go back to the macro and Select All(Ctrl + a) and then paste the macro (Ctrl + v).
You should then be able to run the macro.

2016-05-13 10:26:45



what is the syntax for the ("Book2.xlsx").

Do I need to enter the full root of the file, e.g. user/desktop/book2.xlsx;

or just the open workbook ("Book2.xlsx")

2016-04-29 15:42:36


I'm having the same problem as Ahmedin. any help would be appreciated. Thanks

2016-01-06 18:21:42


Please how do i use this code, what are the procedures to implement so as to make it work.

This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.