Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Copying Named Ranges.

Copying Named Ranges

Written by Allen Wyatt (last updated January 3, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


2

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 as that in the original 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
    Next
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, it would be best to use the macro approach.

Note:

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 (2469) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) 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. ...

MORE FROM ALLEN

Understanding Relative and Absolute Addressing

In Excel you can reference a cell in a formula by entering the coordinates for the cell you want to reference. This can ...

Discover More

Controlling the Bold Text Attribute

When processing a document in a macro, you may need to make some of your text bold. It's easy to do using the Bold ...

Discover More

Status Bar Summing No Longer Available

When you select a range of cells, Excel normally displays the sum of those selected cells on the status bar. If the sum ...

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 (menu)

Counting Commas in a Selection

If you have a range of cells in which you want to count all the commas, there are several ways you can derive the figure ...

Discover More

Getting User Input in a Dialog Box

Want to get some input from the users of your workbooks? You can do it by using the InputBox function in a macro.

Discover More

Deriving the Worksheet Name

Excel doesn't provide an easy way to grab the worksheet name for use within a worksheet. Here are some ideas on ways you ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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 more than 7?

2020-12-08 05:54:55

David

I solved the problem by making sure that names are only copied from a specific tab and that the tab exists in the new workbook.


2020-12-08 04:52:08

David

The code in your example https://excel.tips.net/T002469_Copying_Named_Ranges.html generates an error (1004) in Excel 2019


This Site

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

Newest Tips
Subscribe

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.