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: Using Named Ranges in a Macro.

Using Named Ranges in a Macro

by Allen Wyatt
(last updated April 20, 2013)


Bruce has a named range (Account) defined in a workbook and he wonders how to access and use that named range from within a macro. There are several ways you can access the range, using either the Range object or the Names collection.

To access the named range using the Range object, all you need to do is provide the name of the range as a parameter to the object. This name is the same one that you defined within Excel. For instance, the following line could be used to change the interior color of the entire range:

Worksheets("Sheet1").Range("Account").Interior.Color = vbYellow

Note that the Range object is used relative to a particular worksheet, in this case Sheet1. You could also define a range object within VBA and then assign it to be equal to the named range, in this manner:

Set rng = Worksheets("Sheet1").Range("Account")

The other method of using the named range is to use the Names collection. The following line will again set the interior color of the range to yellow:

Workbooks("Book1.xls").Names("Account").RefersToRange.Interior.Color = vbYellow

Note that the Names collection is relative to the entire workbook, so it is not necessary to know which worksheet the named range is associated with when you use this method of access. You can also define a range object in VBA and assign it to be the same as the named range:

Set rng = Workbooks("Book1.xls").Names("Account").RefersToRange

You should know that the Names collection method of accessing a named range will only be viable if you don't have the same named range defined on different worksheets in the workbook. If you do, then you will need to use the Range object method, which requires the use of a specific worksheet name in the reference.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3106) 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: Using Named Ranges in a Macro.

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. ...


Forcing the Properties Dialog Box to Appear

Do you want the Properties dialog box to appear when you first save a Word document? You can configure Word so that it does ...

Discover More

Appending to a Non-Document Text File

Your macros can easily add information to the end of an existing text file. This is done by opening the target file in Append ...

Discover More

Looking Up Antonyms

Antonyms are words that have opposite meanings. The grammar tools available in Word can suggest antonyms for some words. If ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

Self-Deleting Macros

Macros are very powerful, but you may not want them to always be available to a user. Here are some ways you can limit their ...

Discover More

Trouble Recording Paste Special Formula

Sometimes, when you upgrade to a new version of Excel, you could run into a problem recording macros that you had no problem ...

Discover More

Stepping Through a Macro with a Worksheet Visible

When developing a macro, it is often necessary to step through the various code lines so you can see what is happening on the ...

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}] 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 6 + 0?

2016-12-28 21:06:43

Randy Downs

Nice reference. I ended up using ThisWorkbook since my macro ran within the active workbook.

2016-07-21 05:19:22



I am trying to use a name range within the consolidate function but I get an error 1004.

Sub consolidate()
Dim conso As Range

Selection.Offset(2, 2).Select
Set conso = Selection

LastRow = Cells(Cells.Rows.Count, "C").End(xlUp).Row + 5
Range("C" & LastRow).Select

Selection.consolidate Sources:= _
Range("conso"), Function:= _
xlSum, TopRow:=False, LeftColumn:=True, CreateLinks:=False

End Sub '

I have tried to search online but couldn't find any info on the consolidate function and naming a range in the function.
Any thoughts?

2016-04-15 10:19:40


I am trying to retrieve the column number of a named range in a sheet, using a concatenation of two string object variable Raw_point and Raw_list_name, like this:

Run_value_column = Run_wb.Names(Raw_point & "_" & Raw_list_name).RefersToRange.column

Unfortunately the code does not work(Application-defined or object-defined error), although it does when I refer to the named range directly between "". Is there a way to use Names() with object variables?
Thank you.


2016-03-26 10:50:06

S One

Just to confrim, I use excel 2003 and have found this site very useful.

2015-09-02 05:39:35


When I set the range from another sheet that isn't active vba gives an error and macro doesn't proceed until I select that sheet.
How can I do that? Is it Possible

2015-03-16 15:23:50



But people still use the old versions. That's why this site exists.

If you want tips for the newer versions (including the ones you noted), click the links on this page that lead to those tips--there are plenty of them here!


2015-03-16 15:13:43

Scott Lothrop

It's time to update your tips, current versions of Excel are 2010 and 2013. None of the versions you list are even supported.

2014-12-02 15:31:01

Bob Thing

The active workbook is ActiveWorkbook, so ActiveWorkbook.Names("Account") will access the named range "Account" in the current workbook.

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

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.