How do you create a dynamic formula with INDIRECT
The INDIRECT function in Excel is used to create dynamic references in formulas, allowing you to change references to ranges, cells, or worksheets based on text or variables. This can be particularly useful when you want to create flexible formulas where the referenced range or cell can change depending on user input or other conditions.
Syntax
INDIRECT(ref_text, [a1])
ref_text: This is a reference supplied as a text string. It can be a cell reference, a named range, or even a text that represents a valid cell or range reference.a1(optional): This determines the reference style. If TRUE or omitted,ref_textis interpreted in the A1 reference style (e.g.,A1,B2). If FALSE, it’s interpreted in the R1C1 style (e.g.,R1C1,R2C2).
How INDIRECT Works
INDIRECT returns the reference specified by the ref_text argument. The key is that this reference is dynamic, meaning it can change based on the formula or value in another cell.
Example 1: Basic Use of INDIRECT
Let’s say you want to reference a cell dynamically. If you enter the text B3 in cell A1 and want to return the value of B3, you can use:
=INDIRECT(A1)
- If cell
A1contains the textB3, the formula will return the value in cellB3.
Example 2: Using INDIRECT with Different Sheets
You can use INDIRECT to reference cells from different sheets dynamically. For example, if you want to pull data from a different sheet where the sheet name is stored in cell A1:
=INDIRECT("'" & A1 & "'!B2")
- If cell
A1contains the text "Sheet2", this formula will reference cellB2from the "Sheet2" worksheet.
Example 3: Dynamic Ranges
Let’s say you want to sum values from a dynamic range. The range (A1
or A1) is determined by a number in another cell, such as cell B1. You can use:
excel
Copy code
=SUM(INDIRECT("A1:A" & B1))
- If cell
B1contains5, this formula sums the rangeA1:A5. If you changeB1to10, it will sum the rangeA1:A10.
Example 4: Referencing Named Ranges
If you have a named range in Excel (e.g., "SalesData"), you can reference it dynamically:
excel
Copy code
=INDIRECT("SalesData")
This can be useful if the named range can change based on conditions or user input.
Practical Applications of INDIRECT
- Switching between different datasets: You can store the names of different sheets or ranges in a cell and have a formula that adapts based on that.
- Dynamic charts: If you use
INDIRECTin a chart, it can adapt to show different data depending on user input. - Flexible formulas in templates: In reports or models where input cells vary,
INDIRECTlets formulas remain adaptable without needing manual changes.
Important Notes:
- Volatile function:
INDIRECTis a volatile function, meaning it recalculates every time the worksheet changes. This can slow down your workbook if used excessively. - Text-based references: Since
INDIRECTworks with text references, any error in constructing the text (such as an incorrect sheet name or cell address) will result in an error.
INDIRECT is powerful for creating flexible, dynamic formulas that can adjust based on different conditions or user inputs.