How to define range based on another cell value in Excel?

To calculate a range of values is easy for most of Excel users, but have you ever tried to calculate a range of values based on the number in a specific cell? For example, there is a column of values in column A, and I want to calculate the number of values in column A based on the value in B2, which means that if it is 4 in B2, I will average the first 4 values in column A as below screenshot shown. Now I introduce a simple formula to quickly define range based on another cell value in Excel.
doc define range by cell value 1

Define range based on cell value


arrow blue right bubble Define range based on cell value

To do calculation for a range based on another cell value, you can use a simple formula.

Select a blank cell which you will put out the result, enter this formula =AVERAGE(A1:INDIRECT(CONCATENATE("A",B2))), and press Enter key to get the result.
doc define range by cell value 2

Note:

1. In the formula, A1 is the first cell in the column you want to calculate, A is the column you calculate for, B2 is the cell you calculate based on. You can change these references as you need.

2. If you want to do summary, you can use this formula =SUM(A1:INDIRECT(CONCATENATE("A",B2))).

3. If the first data you want to define is not in first row in the Excel, for instance, in cell A2, you can use the formula as this: =AVERAGE(A2:INDIRECT(CONCATENATE("A",ROW(A2)+B2-1))).
doc define range by cell value 2


Quickly Count/Sum cells by background or format color in Excel

In some cases, you may have a range of cells with multiple colors, and what you want is to count/sum values based on same color, how can you quickly calculate?
With Kutools for Excel's Count by Color, you can quickly do many calculations by color, and also can generate a report of the calculated result.  Click for free full featured trial in 30 days!
doc count by color 1
 
Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days.

The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Xander · 3 days ago
    Hi quick question. My formula =SUMIFS(DATA!$D$5:$D$13914,DATA!$E$5:INDIRECT(CONCATENATE("$E$",C3)),"<"&"1/1/2016") has a range that is from another tab called "DATA." I keep getting #VALUE! errors for this formula. Any suggestions? thanks!
  • To post as a guest, your comment is unpublished.
    Cathy · 18 days ago
    Earlier I posted: Great formula but why does it only work when referring to the first cell. In other words, if you move the whole range down and the first cell in the range is A5 instead of A1, the formula ceases to work.

    After playing with it, I figured out why the formula is not working when the starting row is not row 1. Excel interprets this as the range being A1 thru A4. If you are starting with a different row than row 1, here is how to modify the formula assuming the range now starts with A5:
    =MAX(A5:INDIRECT(CONCATENATE("A",ROW(A5)+B2)))
    This works because the concatenation sees the row reference as fixed in the first example, but it becomes relative in the second example. Hope that helps!

    Jared - You can just subtract 4 instead of adding. =MAX(A5:INDIRECT(CONCATENATE("A",ROW(A5)-B2))) [Assuming you have 4 in cell B2, or you could just leave the formula as is and put -4 in cell B2.]
    • To post as a guest, your comment is unpublished.
      Sunny · 11 days ago
      Hi,cathy, thanks for your supplement, I have test your formula, I think the correct formula may be =MAX(A5:INDIRECT(CONCATENATE("A",ROW(A5)+B2-1))). I have update the tutorual. Thanks again.
  • To post as a guest, your comment is unpublished.
    Cathy · 18 days ago
    Great formula but why does it only work when referring to the first cell. In other words, if you move the whole range down and the first cell in the range is A6 instead of A1, the formula ceases to work. That seems strange.
  • To post as a guest, your comment is unpublished.
    Jared · 24 days ago
    What if I want to count upward from a cell rather than downward? In the above example, the formula starts with A1 and goes downward. Let's say I want a range of 4 cells, beginning with Cell A10 and going to A6. Thank you!
    • To post as a guest, your comment is unpublished.
      Cathy · 18 days ago
      Jared - See my most recent post for how to solve this.

  • To post as a guest, your comment is unpublished.
    Ryan Sojak · 7 months ago
    Can I use this syntax while referring to a different sheet?
    • To post as a guest, your comment is unpublished.
      Narendra · 5 months ago
      If you want to sum referring to a Different Shet In CONCATENATE formula write [ SHEET NAME+COLUMN+ROW]
      Formula=SUM(INDIRECT(CONCATENATE("Sheet1!","D",1)):INDIRECT(CONCATENATE("Sheet1!","D",5)))
  • To post as a guest, your comment is unpublished.
    Jad · 3 years ago
    Hi,

    Thank you so much for your help, but I have a small problem that is I don't have just one column but several ones (about 100 columns) is there a way to change the formula to accommodate the change in columns so O can get the sum for Columns A B C and so on.

    thanks for your help
    • To post as a guest, your comment is unpublished.
      Sunny · 2 years ago
      Thank u for your message. If you want to sum first n values across multiple continuous columns, just change A to the last column you ues. EG, sum first 5 values across column A to column D, apply this formula =SUM(A1:INDIRECT(CONCATENATE("D",F2))).