Search code examples
vbasortingmedian

How to manually calculate the median in VBA?


If (temp = 8) Then
med = 0
Else
med = Application.Median(TP.Columns(j))
End If

Instead of using the in built function Application.Median, how do I calculate the median?


Solution

  • Instead of using in built functions you can create an array to store all your values and then get the median value by arranging the values and getting the one in array length/2.

    If your array length / 2 is a decimal value you will have to get the values of rounding up and rounding down the array length/2, adding them and the dividing them by 2.