Find Median value in an array

Kriskros07

New Member
Joined
Sep 1, 2011
Messages
11
Hi,

I have an unsorted column of values which range between 0 and 100. Using VBA formula i need to return the median (in terms of sorted position) value. An added complexity is that i only wish to look at values in the range (column) which meet criteria against another column. e.g consider the following table where we wish to find the median value where column 1 = B

A 1
B 4
C 2
B 2
D 9
B 56

There are 3 values for B and the median would therefore be 4.

Any help would be greatly appreciated
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi,

I have an unsorted column of values which range between 0 and 100. Using VBA formula i need to return the median (in terms of sorted position) value. An added complexity is that i only wish to look at values in the range (column) which meet criteria against another column. e.g consider the following table where we wish to find the median value where column 1 = B

A 1
B 4
C 2
B 2
D 9
B 56

There are 3 values for B and the median would therefore be 4.

Any help would be greatly appreciated

=MEDIAN(IF(A2:A6="B",B2:B6))

Confrim Control+Shift+Enter

or vba:
Code:
Sub MedianIf()
    Selection.FormulaArray = "=MEDIAN(IF(R2C1:R6C1=""B"",R2C2:R6C2))"
End Sub
 
Last edited:
Upvote 0
Thanks for your reponse greatly appreciated!
Can i only use RC formula here or can i use absolute (paramaterised) references e.g. on another sheet?
I need to do further processing on the retured value. Is the array classed as a variant? will i need to convert it to output as a string value as i need to add a % sign
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,633
Members
452,661
Latest member
Nonhle

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