Dynamic Range

HMN93

New Member
Joined
May 31, 2014
Messages
20
Hello,
I would like to ask for help on this issue.
I have a list of items and cost and I need to find the median for every set of item
example:

[TABLE="width: 500"]
<tbody>[TR]
[TD]item[/TD]
[TD]Cost[/TD]
[TD]Median[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]apple[/TD]
[TD]3[/TD]
[TD]apple[/TD]
[TD]3.75[/TD]
[/TR]
[TR]
[TD]apple[/TD]
[TD]2.8[/TD]
[TD]orange[/TD]
[TD]4.3[/TD]
[/TR]
[TR]
[TD]apple[/TD]
[TD]5.3[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]apple[/TD]
[TD]4.5[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]orange[/TD]
[TD]2.3[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]orange[/TD]
[TD]4.3[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]orange[/TD]
[TD]5.7[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]orange[/TD]
[TD]4.3[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]orange[/TD]
[TD]3.5[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]orange[/TD]
[TD]6.1[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]orange[/TD]
[TD]3.9[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I am trying to do this in excel vba
how can I write the macro to find the median for each item?
I thought of a for loop but I am stuck when it comes to how to write the range so I will be dynamic

Any help is greatly appreciated!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Do you require VBA? There is a simple formula solution which I'll provide in case it suffices.

Does this meet your needs?

<
Excel 2012
ABCDEF
1itemCostMedianMedian
2apple3apple3.93.9
3apple2.8orange4.34.3
4apple5.3pear5151
5apple4.5mango110110
6orange2.3
7orange4.3
8orange5.7
9orange4.3
10orange3.5
11orange6.1
12orange3.9
13pear51
14mango110
Sheet49
Cell Formulas
RangeFormula
E2=SUMIFS($B$2:$B$14,$A$2:$A$14,D2)/COUNTIFS($A$2:$A$14,D2)
E3=SUMIFS($B$2:$B$14,$A$2:$A$14,D3)/COUNTIFS($A$2:$A$14,D3)
E4=SUMIFS($B$2:$B$14,$A$2:$A$14,D4)/COUNTIFS($A$2:$A$14,D4)
E5=SUMIFS($B$2:$B$14,$A$2:$A$14,D5)/COUNTIFS($A$2:$A$14,D5)
F2=SUMIFS($B:$B,$A:$A,D2)/COUNTIFS($A:$A,D2)
F3=SUMIFS($B:$B,$A:$A,D3)/COUNTIFS($A:$A,D3)
F4=SUMIFS($B:$B,$A:$A,D4)/COUNTIFS($A:$A,D4)
F5=SUMIFS($B:$B,$A:$A,D5)/COUNTIFS($A:$A,D5)
 
Upvote 0
DRSteele, thank you for your reply.
doesn't the sum/count return the mean? As for using vba, the next step is to calculate MAD (median absolute deviation) and this computation is part of a long excel sheet and I need to use vba to compute everything.

 
Last edited:
Upvote 0
Yes, it counts mean. I misread - my apologies. I cannot help with VBA...sorry and good luck.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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