Dynamic Range

nigelk

Well-known Member
Joined
Aug 30, 2008
Messages
537
Hi all,

I have a data set in column A, and (for example) 2 in B1 and 10 in C1

How can I create a formula that look at the figures in B1 and C1, and gives me the average of A2:A10

The next time it could be the average of A15:A30 (whatever the figures are in B1 and C1

Thanks,Nigel
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
The most obvious way, I think, might be:

=AVERAGE(INDIRECT("A" & B1 & ":A" & C1))

This would probably be a better way in that it's more efficient/not volatile:

=AVERAGE(INDEX(A:A,B1):INDEX(A:A,C1))
 
Upvote 0
Thanks, I've tried that but it's including numbers above the upper limit.

I tried 2 and 5 (A2:A5) and then put other figures in A6:A7, and they got included as well.

Nigel.
 
Upvote 0
Thanks, I've tried that but it's including numbers above the upper limit.

I tried 2 and 5 (A2:A5) and then put other figures in A6:A7, and they got included as well.

Nigel.
Which one did you try that's not working properly?

They both work for me but I'd use this version:

=AVERAGE(INDEX(A:A,B1):INDEX(A:A,C1))

Note that if either or both cells B1, C1 are empty then the formula will calculate the entire column A.
 
Upvote 0
Hi Nigel,

On second glance the formula seems to work for me too...

To illustrate Biff's point (which is something that hadn't occurred to me, and I still don't understand how it works to return the whole column...):
Excel Workbook
ABCD
12525
21028307.1429
3202100461.1111
4305461.1111
5402461.1111
650
71000
81000
91000
101000
Sheet1
Cell Formulas
RangeFormula
D1=AVERAGE(INDEX(A:A,B1):INDEX(A:A,C1))


Hope that helps.
Tai
 
Last edited:
Upvote 0
Hi Nigel,

On second glance the formula seems to work for me too...

To illustrate Biff's point (which is something that hadn't occurred to me, and I still don't understand how it works to return the whole column...):

Excel Workbook
ABCD
12525
21028307.1429
3202100461.1111
4305461.1111
5402461.1111
650
71000
81000
91000
101000
Sheet1
Cell Formulas
RangeFormula
D1=AVERAGE(INDEX(A:A,B1):INDEX(A:A,C1))



Hope that helps.
Tai
If the row_number argument evaluates to 0 then the entire referenced range is calculated.

INDEX(A:A,B1)

So, if B1 is an empty cell (empty cells evaluate to 0), then the entire column A is calculated in the formula.
 
Upvote 0
Thanks to both of you for explaining that one - I guess in the back of my mind I knew that index(A:A,0) returns the whole column but was getting confused about constructing a reference with two index() functions as (Index)":"(Index)...where that evaluates to (A:A)":"(A5) for example.

Tai
 
Upvote 0
Thanks to both of you for explaining that one - I guess in the back of my mind I knew that index(A:A,0) returns the whole column but was getting confused about constructing a reference with two index() functions as (Index)":"(Index)...where that evaluates to (A:A)":"(A5) for example.

Tai
Yes, and since (A5) falls within (A:A), then the final evaluation is simply A:A.
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,219
Members
452,895
Latest member
BILLING GUY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top