Go back
MS Excel Question

MS Excel Question

General

Nemesio
Ursulakantor

Pittsburgh, PA

Joined
05 Mar 02
Moves
34824
Clock
20 Jul 08
1 edit
Vote Up
Vote Down

I'm trying to do something like the following. Let's say I have a string of data in A1:A10. I
know I can take the average of these data (say in cell B1) 'AVERAGE(A1:A10)' but what I want
to do is make something a little more flexible. Sometimes I want to know the average between
A1:A4, sometimes I want to know the average between A3:A8, &c.

I want to have two cells (call them C1 and C2) whose values change the range of the average.
That is, I want to make the average A[C1]:A[C2], such that I can change C1 and C2 and get the
particular average I am looking for.

Any ideas?

Nemesio

Ragnorak
For RHP addons...

tinyurl.com/yssp6g

Joined
16 Mar 04
Moves
15013
Clock
20 Jul 08
1 edit
Vote Up
Vote Down

Originally posted by Nemesio
I'm trying to do something like the following. Let's say I have a string of data in A1:A10. I
know I can take the average of these data (say in cell B1) 'AVERAGE(A1:A10)' but what I want
to do is make something a little more flexible. Sometimes I want to know the average between
A1:A4, sometimes I want to know the average between A3:A8, &c.

I want ...[text shortened]... change C1 and C2 and get the
particular average I am looking for.

Any ideas?

Nemesio
Here's a good page explaining programming loops in VB...
http://computerprogramming.suite101.com/article.cfm/how_to_loop_in_cell_range_in_excel

D

Nemesio
Ursulakantor

Pittsburgh, PA

Joined
05 Mar 02
Moves
34824
Clock
20 Jul 08
Vote Up
Vote Down

Originally posted by Ragnorak
Here's a good page explaining programming loops in VB...
http://computerprogramming.suite101.com/article.cfm/how_to_loop_in_cell_range_in_excel

D
Er. I don't understand any of that. I'm a novice at spreadsheets, I don't know a thing about Visual
Basic.

Is it impossible in Excel by itself?

Nemesio

n
The Conductor

With the band

Joined
14 Jun 07
Moves
41110
Clock
21 Jul 08
Vote Up
Vote Down

Originally posted by Nemesio
I'm trying to do something like the following. Let's say I have a string of data in A1:A10. I
know I can take the average of these data (say in cell B1) 'AVERAGE(A1:A10)' but what I want
to do is make something a little more flexible. Sometimes I want to know the average between
A1:A4, sometimes I want to know the average between A3:A8, &c.

I want ...[text shortened]... change C1 and C2 and get the
particular average I am looking for.

Any ideas?

Nemesio
I would use the True/False and IF:THEN formulas. For instance, In D1 I might have the True/False formula to display a 1 for true and a 0 for false. Then in B1 I might have it set up for if D1=1/then AVG.A1:A3. If D1=0/then AVG. A3:A10.

Try that.

np

C
Not Aleister

Control room

Joined
17 Apr 02
Moves
91813
Clock
21 Jul 08
4 edits
Vote Up
Vote Down

There may be an easier way, but I don't know of it.

In your sheet you want to use, press Alt+F11, bringing up the VB Editor.
Double click on your sheet in the left pane and then paste this code (all italics):


Sub getAvg()

Dim bottom, top

bottom = ActiveSheet.Range("C1" )
top = ActiveSheet.Range("C2" )

ActiveSheet.Range("E1" ).Select
ActiveCell.Value = "=average(" & bottom & ":" & top & " ) "

End Sub


Cell C1 will be the 'bottom' range value and C2 the top range value.
Cell E1 will hold the formula and end result.

Close the editor and back on your Excel sheet press Alt+F8 to bring up the macro dialog. You should see something like 'Sheet1.getAvg'. Just click Run.


Et voila.


EDIT You can change the cell values easily enough in the function to reflect what you need. Just make sure that you enter the range cell values (in the format: A1 or A12 etc.) in the correct cells after changing it in the function and be sure to remember the function will overwrite whatever was in the 'result' cell before running the macro.


EDIT! Stupid smileys! 😠

P
Upward Spiral

Halfway

Joined
02 Aug 04
Moves
8702
Clock
21 Jul 08
1 edit
Vote Up
Vote Down

=AVERAGE(Indirect(C1):Indirect(C2))

Then just write the starting cell reference in C1 and the ending cell reference in C2.

C
Not Aleister

Control room

Joined
17 Apr 02
Moves
91813
Clock
21 Jul 08
Vote Up
Vote Down

Originally posted by Palynka
=AVERAGE(Indirect(C1):Indirect(C2))

Then just write the starting cell reference in C1 and the ending cell reference in C2.
Ha! That's the one!

I knew there should be something like that...

P
Upward Spiral

Halfway

Joined
02 Aug 04
Moves
8702
Clock
21 Jul 08
Vote Up
Vote Down

Originally posted by Crowley
Ha! That's the one!

I knew there should be something like that...
😏

Nemesio
Ursulakantor

Pittsburgh, PA

Joined
05 Mar 02
Moves
34824
Clock
21 Jul 08
Vote Up
Vote Down

Originally posted by Palynka
=AVERAGE(Indirect(C1):Indirect(C2))

Then just write the starting cell reference in C1 and the ending cell reference in C2.
Perfect! Thank you so much, Palynka.

And thanks so much to everyone else who tried to give me another way, albeit ones beyond
my Excel capacity.

You rock, Palynka!

Nemesio

P
Upward Spiral

Halfway

Joined
02 Aug 04
Moves
8702
Clock
21 Jul 08
Vote Up
Vote Down

Originally posted by Nemesio
Perfect! Thank you so much, Palynka.

And thanks so much to everyone else who tried to give me another way, albeit ones beyond
my Excel capacity.

You rock, Palynka!

Nemesio
Stop it... You're making me blush... 😳

P
Bananarama

False berry

Joined
14 Feb 04
Moves
28719
Clock
21 Jul 08
Vote Up
Vote Down

Originally posted by Palynka
Stop it... You're making me blush... 😳
Got any other tricks? I use Excel all the time (just ask those other nerds in the Posers & Puzzles forum), so any tricks will be put to good use, gar-ohn-teed!

P
Upward Spiral

Halfway

Joined
02 Aug 04
Moves
8702
Clock
21 Jul 08
Vote Up
Vote Down

Originally posted by PBE6
Got any other tricks? I use Excel all the time (just ask those other nerds in the Posers & Puzzles forum), so any tricks will be put to good use, gar-ohn-teed!
I don't know... I find the Offset function to be handy, if you want to pick out elements in a matrix.

It's hard to say... What do you want to do?

Cookies help us deliver our Services. By using our Services or clicking I agree, you agree to our use of cookies. Learn More.