Search Contextures Sites

Learn how to create Excel dashboards.

 

Related Tutorials

 

30 Excel Functions in 30 Days

 

Contextures
Excel news
by email

 

 

 

Learn how to create Excel dashboards.

 

 

 

Your worksheet formulas can create traffic-light charts, highlight chart elements, assign number formats, and more.

 

 

 

 

 

Learn how to create Excel dashboards.

 

 

 

Learn how to create Excel dashboards.

 

 

Live-link your Excel dashboards to nearly any web data.

 

 

 

Learn how to create Excel dashboards.

 

 

 

 

 

Excel INDIRECT Function

Thanks to Dave Peterson, for his contributions to this page.

INDIRECT Function Arguments 
Lock a Cell Reference 
Video: INDIRECT Function
Create a Reference from a Cell Value 
Create a Reference from a Cell Value and Text 
Create a Reference to a Different Sheet 
Create a Reference to a Different Workbook 
Refer to a Named Range  
Dependent Data Validation Lists 
Download the Sample File
More Function Tutorials

The INDIRECT function returns a reference to a range. You can use this function to create a reference that won't change if row or columns are inserted in the worksheet. Or, use it to create a reference from letters and numbers in other cells.

INDIRECT Function Arguments

The INDIRECT function has two arguments:

  1. ref_text: A cell reference or text string (or both), that create the range reference. The referenced range can be a cell, a range of cells, or a named range.
  2. a1: TRUE or FALSE. Does the reference use A1 reference style? If this argument is TRUE, or omitted, the ref_text is A1 style. If the argument is FALSE, the ref_text is R1C1 style.

Note: If the INDIRECT formula refers to a different workbook, that workbook must be open, or the formula will return a #REF! error.

Lock a Cell Reference

If you create a simple link to a cell, e.g. =A4, then insert a row above row 4, your formula will automatically change to =A5. To prevent this change, you can use the INDIRECT function.

To demonstrate the difference, you'll create two formulas -- one that uses a simple link, and one that uses a text string with an INDIRECT function.

  1. In cell A4, type a number (10 in this example).
  2. In cell B2, type the following formula: 
       =INDIRECT("A4")
  3. Press the Enter key, and the formula will return the number in cell A4.
  4. In cell C2, type the following formula: 
       =A4
  5. Press the Enter key, and the formula will return the number in cell A4. 
  6. To insert a row, right-click on the Row 4 button, and from the pop-up menu, choose Insert.
  7. As shown below, cell B2, which uses the INDIRECT function, now returns 0, because cell A4 is empty. The text string, "A4", in the INDIRECT formula did not change when the row was inserted.
  8. Cell C2, which contains the link, still returns 10, because its formula has changed to =A5.

Video: INDIRECT Function

To see the steps for creating a formula with the INDIRECT function, please watch this video tutorial.

Create a Reference from a Cell Value

To create the ref_text argument, you can also refer to a cell, and use its contents. This makes the formula more flexible, as its results will change, if the cell contents change.

In this example, you'll create formulas with the INDIRECT function, to compare the A1 and R1C1 reference styles.

  1. In cells A1:A5, type a set of numbers, as shown below.
  2. In cell C2, type:  A4
  3. In cell C2, type:  R4C1
  4. In cell D2, type the formula: =INDIRECT(C2)
  5. Press the Enter key, and the formula returns the number in cell A4
  6. In cell D3, type the formula: =INDIRECT(C3,FALSE)
  7. The FALSE in the second argument indicates that the R1C1 reference style will be used.
  8. Press the Enter key, and the formula returns the number in cell A4

Create a Reference from a Cell Value and Text

To create the ref_text argument, you can combine text strings and cell references within an INDIRECT function.

In this example, you'll create a formula with the INDIRECT function, using a number entered in a cell, and a text string with the column letter.

  1. In cells A1:A5, type a set of numbers, as shown below.
  2. In cell C2, type the number 4.
  3. In cell D2, type the formula: =INDIRECT("A"&C2)
  4. Press the Enter key, and the formula returns the number in cell A4
  5. Change the number in cell C2, and the result in D2 will change.

Note: If cell C2 is empty, the formula will return an error. To prevent this, you can add an IF function:
     =IF(C2="",0,INDIRECT("A"&C2))

Create a Reference To a Different Sheet

An INDIRECT formula can also refer to cells on other worksheets. In this example, you'll create a formula with the INDIRECT function, using references to a sheet name and cell name.

  1. On a worksheet named Data Sheet, enter numbers in cells A1:A10
  2. On a different sheet, in cell A2, enter the sheet name: Data Sheet
  3. In cell B2, type a cell name from the range of numbers, e.g.: A2
  4. In cell C2, type the following formula:
    =INDIRECT("'" & A2 & "'!" & B2)
  5. The first part of the string is a single quote within a set of double quotes:
         " ' "  (spaces were added for clarity)
  6. After the reference to A2, which contains the sheet name, is a single quote and apostrophe, within a set of double quotes:
         " ' ! "  (spaces were added for clarity)
  7. The string ends with a reference to cell B2, which contains the cell address.
  8. Single quotes are included in the string to prevent errors if the sheet name contains space characters.
  9. Press the Enter key, and the formula returns the number in cell A2 on the Data Sheet worksheet.
  10. Change the number in cell C2, and the result in D2 will change.

Note: If either cell A2 or B2 is empty, the formula will return an error. To prevent this, you can add an IF function:

    =IF(OR(A2="",B2=""),"",INDIRECT("'" & A2 & "'!" & B2))    

Create a Reference To a Different Workbook

An INDIRECT formula can refer to cells in other workbooks, but will return a #REF! error if that workbook is closed. In this example, you'll create a formula with the INDIRECT function, using references to a file name, sheet name and cell name.

  1. In an open file named TestFile.xls, on a worksheet named Test Data, enter numbers in cells A1:A10
  2. On a sheet in a different workbook, in cell A2, enter the file name:
         Test File.xls
  3. In cell A3, enter the sheet name: Test Data
  4. In cell A4, type a cell name from the range of numbers, e.g.: A7
  5. To see the syntax that you'll need to use in your formula, select cell A7, and type an equal sign:   =
  6. Switch to Test File.xls, and click on cell A7
  7. In the formula bar, you'll see the reference that was created:
           ='[Test File.xls]Test Data'!$A$7
  8. You'll create an INDIRECT formula that uses the same syntax, adding the single quote marks, square brackets and apostrophe.
  9. In cell A6, type the following formula:
    =INDIRECT("'[" & A2 & "]" & A3 & "'!" & A4)
  10. The first part of the string is a single quote and square bracket, within a set of double quotes:
         " ' [ "  (spaces were added for clarity)
  11. After the reference to A2, which contains the file name, is a square bracket, within a set of double quotes:
         " ] "  (spaces were added for clarity)
  12. After the reference to A3, which contains the sheet name, is a single quote and apostrophe, within a set of double quotes:
         " ' ! "  (spaces were added for clarity)
  13. The string ends with a reference to cell A4, which contains the cell address.
  14. Single quotes are included in the string to prevent errors if the sheet name contains space characters.
  15. Press the Enter key, and the formula returns the number in cell A7 on the Test Data worksheet, in the Test File.xls workbook.
  16. Change the values in cells A2:A5, and the result in A6 will change.
  17. You can delete the sample link in cell A5

Note1: If A2, A3 or A4 is empty, the formula will return an error. To prevent this, you can add an IF function:

     =IF(OR(A2="",A3="",A4=""),"",INDIRECT("'[" & A2 & "]" & A3 & "'!" & A4))

 Note2: If the Test File.xls workbook is closed, the above formula will return a #REF error. I haven't used the following files, but they may help you if you need to pull data from a closed workbook:

Refer to a Named Range

In addition to cell references, you can refer to named ranges in an INDIRECT formula. In this example, the INDIRECT function is used to sum the selected named range.

  1. In cells A1:B5, type headings and numbers, as shown at right.
  2. Name cells A2:A5 as East, and cells B2:B5 as West. There are naming instructions here:
  3. Names -- Naming Ranges

  4. In cell D2, type the name of one of the ranges, e.g. East
  5. In cell E2, type the formula: =SUM(INDIRECT(D2))
  6. Press the Enter key, and the formula returns the sum of numbers in the East range.
  7. Change cell D2 to West, and the formula returns the sum of numbers in the West range.

Dependent Data Validation Lists

The INDIRECT function can be used with Data Validation, to create dependent dropdown lists. For example, select the Fruit category in column A, and the data validation list in column B shows a list of Fruit options.

There are instructions for this technique here:  

Data Validation - Dependent Lists

Download the Sample File

Download the sample INDIRECT workbook

Functions Tutorials

SUM Function  
VLOOKUP Function  
INDEX function and MATCH Function   
Count Function  
INDIRECT Function  

Get All the Excel News

For regular Excel news, tips and videos, please sign up for the Contextures Excel newsletter. Your email address will never be shared with anyone else.

Search Contextures

Search Contextures Sites

 

 

 

Privacy Policy

 

Contextures Inc., Copyright 2014
All rights reserved.

 

Last updated: December 18, 2014 11:10 AM