ThisCalculator

Everyday

Define Range Based on Cell Value

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

Range based on cell value means a dynamically sized group of cells in a spreadsheet that expands or contracts depending on a number you type into a specific cell. You enter the starting cell and a count (or an end condition), and the range automatically includes only the cells that meet that rule. This is essential for building dashboards, charts, and formulas that stay accurate as your data grows.

Formula

The core idea is to build a range address as a text string and then convert that text into a real range reference. In Excel and Google Sheets, the standard functions are INDIRECT (Excel) and INDIRECT (Sheets) or OFFSET. The general formula is:

=INDIRECT("A"&start_row&":A"&(start_row+count-1))

Where:

  • start_row – the row number of the first cell (a positive integer).
  • count – the number of rows you want to include (a positive integer).
  • A – the column letter (can be replaced with any column).

The expression start_row + count - 1 gives the last row number. For example, if start is 1 and count is 10, the last row is 10, so the range is A1:A10.

Worked Example

Using the defaults from the calculator above (start row = 1, count = 10):

  1. First cell: "A" & 1 → A1
  2. Last cell: "A" & (1 + 10 - 1) → A10
  3. Range address: "A1:A10"

So the formula =SUM(INDIRECT("A1:A10")) would sum exactly the values in A1 through A10. If you change the count cell to 15, the range automatically becomes A1:A15.

Why Use a Dynamic Range?

Static ranges like A1:A10 are fine for one-time calculations, but they break when you add or remove data. If you add an 11th row, a static formula won’t include it unless you manually edit the formula. A range based on a cell value solves this by letting you control the size from a single input cell. This is especially useful for:

  • Charts that should always show the latest data points.
  • Dashboards where the user selects how many months to display.
  • Data validation lists that need to grow with new entries.
  • Formulas like SUM, AVERAGE, or COUNT that should only cover a specific number of rows.

How to Implement in Excel and Google Sheets

There are two main approaches: INDIRECT and OFFSET.

Using INDIRECT:

  1. Put your start row number in a cell (e.g., B1) and your count in another (e.g., B2).
  2. In a formula, write =SUM(INDIRECT("A"&B1&":A"&(B1+B2-1))).
  3. Change B1 or B2, and the sum updates.

Using OFFSET:

  1. OFFSET returns a range that is a given number of rows and columns from a starting reference.
  2. Example: =SUM(OFFSET(A1,0,0,B2,1)) – this starts at A1, moves 0 rows and 0 columns, then takes a height of B2 rows and a width of 1 column.
  3. Here B2 holds the count. OFFSET is more flexible because you can also offset the starting point.

Both work in Excel and Google Sheets. INDIRECT is often easier to read, but OFFSET is more efficient in large workbooks because it doesn’t recalculate text strings.

Common Mistakes and How to Avoid Them

  • Off-by-one errors: The last row is start + count - 1, not start + count. In the example, start=1, count=10 gives last row 10, not 11.
  • Using text instead of numbers: If the start or count cells contain text (e.g., “10” with an apostrophe), the formula fails. Ensure they are numeric.
  • Forgetting to lock references: When copying formulas, use absolute references like $B$1 to keep the control cells fixed.
  • Mixing row and column counts: OFFSET’s height and width arguments are separate. If you only want one column, width must be 1.
  • Using INDIRECT with volatile functions: INDIRECT is volatile – it recalculates every time the sheet changes. In very large sheets, this can slow down performance. OFFSET is also volatile, but often less so.

Alternatives to Cell-Value Ranges

If you don’t want to manually type a count, you can use other dynamic methods:

  • Excel Table: Convert your data to a Table (Ctrl+T). Then use structured references like =SUM(Table1[Sales]) – the range automatically includes all rows in the table, even new ones.
  • Dynamic Array Formulas: In Excel 365 and Google Sheets, formulas like =FILTER(A:A, A:A<>"") return a dynamic array that automatically resizes.
  • Named Ranges with OFFSET: Create a named range that uses OFFSET to define a dynamic area, then reference that name in formulas.
  • COUNTA to find last row: Use =COUNTA(A:A) to count non-empty cells and use that as the count in your INDIRECT or OFFSET formula.

Frequently Asked Questions

What is the difference between INDIRECT and OFFSET?

INDIRECT converts a text string into a reference. OFFSET returns a reference that is a certain number of rows and columns away from a starting cell, with a specified height and width. INDIRECT is easier to build with concatenation, but OFFSET is more flexible for moving the start point.

Can I use a cell value to define a range in a chart?

Yes. In Excel, you can define a named range using INDIRECT or OFFSET, then use that name as the chart’s data source. In Google Sheets, you can use dynamic arrays or named ranges with OFFSET. The chart will update when the cell value changes.

Why does my INDIRECT formula return a #REF! error?

This usually means the text string does not form a valid reference. Check that the column letter is correct, the row numbers are positive, and that the sheet name (if included) is spelled correctly. Also ensure the start and count cells contain numbers, not text.

How do I make the range automatically adjust to the last non-empty cell?

Use =COUNTA(A:A) to get the number of non-empty cells in column A, then use that as the count in your INDIRECT or OFFSET formula. For example: =SUM(A1:INDEX(A:A,COUNTA(A:A))).

Is there a performance difference between INDIRECT and OFFSET?

Yes. Both are volatile, meaning they recalculate whenever any change occurs in the workbook. In large spreadsheets, this can cause noticeable slowdowns. OFFSET is generally slightly faster than INDIRECT because it doesn’t parse text, but both should be used sparingly if performance is critical.

Can I use a cell value to define a range in a data validation list?

Yes. In Excel, you can define a named range that uses INDIRECT or OFFSET, then use that name in the data validation source. In Google Sheets, you can use a range like =Sheet1!A1:A if you have a dynamic array, or use a custom formula with INDIRECT.

Related

Formula used
in start | Start row | - | 1 | 1
in count | Number of rows | - | 10 | 1
out first | First cell | - | "A" & start | 0
out last | Last cell | - | "A" & (start + count - 1) | 0
out range | Range address | - | "A" & start & ":A" & (start + count - 1) | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.