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.

**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!

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 MoreNormally you use the RAND and RANDBETWEEN functions to generate random numbers. What if you want to generate random ...

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

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

2019-05-27 10:34:45

Dennis Costello

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

Here's one suggestion (see the Tip's text):

=IFERROR(INDIRECT("'"&A1&"'!B11"),"Please open "&A1)

2019-02-25 11:28:18

Roy

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

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

=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

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.

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

Copyright © 2019 Sharon Parq Associates, Inc.

## Comments