Indirectly Referencing a Cell on a Different Worksheet

by Allen Wyatt
(last updated February 23, 2019)

6

Michael has a worksheet that has month names (January, February, etc.) in column A. In column B he wants to pull a value from cell B11 of whatever worksheet is specified in column A. Thus, if column A contains the month "March," in the cell just to the right of March (in column B) he wants to pull the value in March!B11. Michael believes that the INDIRECT function should help with this, but he can't get it to work.

The good news is that Michael is correct—you can use the INDIRECT function to do this. The basic usage of the function looks like this:

=INDIRECT(A1&"!B11")

You can build a more "robust" version of the formula by enclosing it within a function that checks for errors. If there is an error, then the phrase "No Data" displays in the cell:

=IFERROR(INDIRECT(A1&"!B11"),"No Data")

These approaches use whatever is in cell A1 directly, which works provided that the value in A1 is text and a single word. If there might be a second word in A1 (such as "July Production"), then you need to modify the formula a bit so that it includes apostrophes around whatever is in cell A11:

=IFERROR(INDIRECT("'"&A1&"'!B11"),"No Data")

Because the apostrophes are used to enclose a worksheet name, you cannot have any text in cell A1 that includes apostrophes. So, "July Production" in cell A1 will work fine (provided you have a worksheet named "July Production"), but "July's Production" will not work because of the apostrophe.

Further, if whatever is in cell A1 may have either leading or trailing spaces on it, then you'll need to get rid of those spaces. The easiest way to compensate is to use the TRIM function:

=IFERROR(INDIRECT("'"&TRIM(A1)&"'!B11"),"No Data")

All of the variations presented so far work just fine if the value in A1 is an actual string. They won't work if the value in A1 is an actual date, formatted to look like a month name. Dates are stored internally as numbers and using one of the formulas discussed so far will try to add the date serial number to the cell reference, which generates an error. Instead, you need to use the TEXT function to convert the date in A1 to a month name:

=IFERROR(INDIRECT(TEXT(A1,"mmmm")&"!B11"),"No Data")

If you are expecting other people to enter month names into cell A1, then you would be well advised to make that entry as fool-proof as possible. The best way to do that is to use data validation to limit what can be entered into cell A1. (How you use data validation has been covered in other issues of ExcelTips.)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12701) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.

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

Adding a Little Color

The normal way to change the color of selected text is through the use of the Font Color tool. If you have to use the ...

Discover More

Forcing the Date to the Next Wednesday

Working with today's date in Word is easy. Trying to manipulate dates to come up with a future one can be an entirely ...

Discover More

Jumping to Tables

If your document contains quite a few tables, you may find it helpful to jump quickly from one table to another. There ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Referencing the Last Six Items in a Formula

If you have a list of data in a column, you may want to determine an average of whatever the last few items are in the ...

Discover More

Generating Double-Digit Random Numbers

Normally you use the RAND and RANDBETWEEN functions to generate random numbers. What if you want to generate random ...

Discover More

Determining "Highest Since" or "Lowest Since"

When compiling statistics on a collection of data points, you may want to know whether a particular value is the "highest ...

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

2019-05-27 10:34:45

Dennis Costello

@David Robinson:

I also can't help you to get INDIRECT to work correctly when it refers to a closed workbook. There is a similar problem with the 4 very helpful functions COUNTIF, COUNTIFS, SUMIF, and SUMIFS. Imagine, for instance, the formula =COUNTIF('[Other Workbook.xlsx]Books'!$K:$K,"Y"). This works properly if the other workbook is open, but if it is not, it will return #VALUE!. Just to make things more confusing, if Other Workbook is open when you enter the formula, it will return the right value; if you close it, that correct value is cached but any other similar formulae you enter will get the #VALUE!. The COUNT, COUNTA, and SUM functions don't have this problem.

An alternative (to COUNTIF) would be to use an array formula of the SUM function: {=SUM( ('[Other Workbook.xlsx]Books'!$K:$K="Y") * 1)}
You could of course use "+ 0" instead of "* 1" in the formula if you'd rather. In either case, the bit inside the inner parens will return an array of TRUE and FALSE values, the * 1 or + 0 turns those into 1 or 0, and the count of TRUE values is identical to the sum of the 1's. I'll leave as an exercise for the reader how to use the same trick to replace the COUNTIFS, SUM, and SUMIFS functions.

Here's an example: i opened "Other Workbook", then entered in "This Workbook", cells A1:B2, the COUNTIF formula in cell A1 and the SUM formula in B1. Both return the correct value. I then closed "Other Workbook", and entered the same formulae on row 2. You can see that the value 708 was cached in cell A1 even though the formula is no longer valid. If you force cell A1 to be recalculated, it will change to #VALUE!, and an Undo won't heal it. In any case, the SUM formula in column B work just fine.

708..............708
#VALUE!......708

Because this workaround literally only occurred to be this morning, I've always used "transfer sheets" to deal with this problem - I'd add a worksheet to "Other Workbook" and put all my COUNTIFS and SUMIFS functions there, with a simple "hard link" from "This Workbook". This is probably what you meant by "using a lot of spreadsheet real estate". Considering that the COUNTIFS and SUMIFS formulae are easier to understand than the SUM workaround, I'll probably continue to use them and pay the price of using transfer sheets.


2019-02-26 11:14:15

J. Woolley

@David Robinson:

Here's one suggestion (see the Tip's text):
=IFERROR(INDIRECT("'"&A1&"'!B11"),"Please open "&A1)


2019-02-25 11:28:18

Roy

You can test for a 'not "G"' format in an IFERROR(), taking the date information if it succeeds in the "usual ways" to provide out to INDIRECT(). And you can have the error result take it as is. You can also wrap all that in another IFERROR() that handles things of an even more unusual nature.

The nested IFERROR() approach can be used lots of places. For some reason, that never seems to come up when it is talked about.

As far as those apostrophes go (for names with spaces), having them when the name is a single word causes NO problems, so just use a formula containing them to handle either of the two situations that might occur. Never bother with not putting them in.


2019-02-25 11:20:51

David Robinson

Unfortunately I can only use INDRECT to point at a cell in an *open* workbook. If I close the file I'm pointing to, the INDIRECT will no longer work (returns #REF!).

I've used various workarounds in the past, most of which use a lot of spreadsheet real estate but do at least work, and of course I can use a macro to set the formula to do the pointing (i.e. the macro sets the cell's formula to a conventional reference using the text that would've been the INDIRECT argument), but can anyone advise if it's possible just using formulas to get INDIRECT to work on a closed workbook?


2019-02-23 11:40:44

J. Woolley

Re. "Because the apostrophes are used to enclose a worksheet name, you cannot have any text in cell A1 that includes apostrophes." I believe this formula will accommodate a name that includes apostrophes:

=IFERROR(INDIRECT("'"&SUBSTITUTE(A1,"'","''")&"'!B11"),"No Data")

In this case, two apostrophes will be substituted for each apostrophe in cell A1 to determine the INDIRECT address.

And since a worksheet's name can include leading and/or trailing space characters, it might not be a good idea to use the TRIM function.


2019-02-23 09:53:06

Fanny Ennever

INDIRECT is powerful when combined with ADDRESS, which lets you do math to select which cells to reference.


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