How to loop through the data to find the median?

F

fl

I have the following spreadsheet. I would like to find the median for
Column B for the associated item in A. For example, for Item 1, get
median(B1:B12); for Item 2, median(B13:B17); Item 3, median(b18:b20)
etc. Is there an example to do this using VBA? Thanks.

A B
= ====
1 1 154000
2 1 556000
3 1 195000
4 1 135000
5 1 154500
6 1 109896
7 1 172000
8 1 250000
9 1 162500
10 1 120000
11 1 100000
12 1 125000
13 2 126000
14 2 167565
15 2 125000
16 2 150000
17 2 90000
18 3 128648
19 3 148740
20 3 125000
21 4 104280
22 4 71500
23 4 109555
24 4 121000
25 4 132720
26 4 114600
27 4 84150
 
J

JWolf

You could do this with an array formula:
In C1 enter the value in column A you want to find the median of column B
In D1 enter the following array formula: =MEDIAN(IF(A1:A27=C1,B1:B27,FALSE))
The array formula must be entered with ctrl+shift+enter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top