Using a Cell Value as a Worksheet Name in a Formula

Written by Allen Wyatt (last updated December 4, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


3

Roy has a formula that references a cell in another workbook, as ='[Timesheets.xlsm]Week01'!L6. He would like to have the formula pick up the name of the worksheet (Week01) from another cell, so that the formula becomes more general-purpose. Roy wonders how he should change the formula so it can use whatever worksheet name is in cell B9.

The easiest way to handle this is to use the INDIRECT worksheet function. Essentially, it takes a cell address and uses it as a "pointer" and then retrieves the value from that cell. For instance, you could use the following:

=INDIRECT(L6)

This results in the value in cell L6 being fetched and used as the pointer to what you really want. Thus, if cell L6 contains "A7", then the function returns the value of whatever is in cell A7. Interestingly, if you invoke the function in this way you get a different result:

=INDIRECT("L6")

The result is the contents of cell L6 instead of using the contents of cell L6 as a pointer.

With this information, you could easily put together an address that will work properly with the INDIRECT function:

=INDIRECT("'[Timesheets.xlsm]" & K2 & "'!L6")

This formula assumes that the name of the desired worksheet is stored in cell K2. If a valid worksheet name is not in that cell the formula returns a #REF error.

One important "gotcha" with this approach is that you've got to make sure that the workbook (Timesheets.xlsm) is open. INDIRECT won't reach into an unopen workbook. If it is not open, then you'll get a #REF error instead of the desired value.

If you want to make the formula even more general-purpose, you could pull the workbook name, worksheet name, and cell referene all from cells within your worksheet, as in this manner:

=INDIRECT("'[" & K1 & "]" & K2 & "'!" & K3)

In this instance, K1 would contain the workbook name (Timesheets.xlsm), K2 would contain the worksheet name ("Week01"), and K3 would contain the cell desired ("L6").

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (6069) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 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 Many No-Width Optional Breaks

One of the special characters you can add in a document is the no-width optional break. Although originally designed for ...

Discover More

Random Numbers in a Range

Excel provides several different functions that you can use to generate random numbers. One of the most useful is the ...

Discover More

Default Cell Movement when Deleting

Delete a cell or a range of cells, and Excel needs to figure out how to rearrange the void left by the deletion. You can ...

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

Returning the Left-most Characters

When working with text in a formula, you may need to extract the left-most characters from a string of text or from a ...

Discover More

Leaving a Cell Value Unchanged If a Condition Is False

Ever want the IF function to only return a value if the condition it is testing is true, and not if the condition is ...

Discover More

Finding the Lowest Numbers

Need to find the lowest numbers in a range of values? It's easy to do using the SMALL worksheet function, or you can use ...

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 6 - 6?

2023-02-10 09:47:10

J. Woolley

@Tom V
Please be more specific. Describe what you want to do. Provide an example.


2023-02-09 13:11:54

Tom V

Can you make L6 dynamic here? So the value in the reference worksheet changes sequentially?


2022-04-08 03:35:47

Erik P

Thanks Alan. I use this alot but always forget syntax with speech marks. This was a very clear explanation.


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.