ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to loop through the data to find the median? (https://www.excelbanter.com/excel-programming/302418-how-loop-through-data-find-median.html)

fl

How to loop through the data to find the median?
 
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



JWolf

How to loop through the data to find the median?
 
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.

fl wrote:
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




All times are GMT +1. The time now is 05:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com