samedi 3 avril 2021

I NEED an excel vba code for calculating the median of a column based on given criteria

Currently I am trying to calculate the median of a column of values based on criteria in another column. Basically, if cells in column A are empty, then I want to find the median of the cells in column B. I know that excel has built in MaxIf, AverageIf, and MInIf functions, however it doesn't appear to have one for median. I tried a different method by offsetting the values in column B to column C if the corresponding cells in column A are empty, however this isnt working for me as I can seem to have differently ranges being used in an if then vba statement at the same time.

Any help would be greatly appreciated.

''' Sub MonthlyHoursWorkedLeft()

MonthlyAverageLeft = 0
MonthlyMedianLeft = 0
MonthlyMinLeft = 0
MonthlyMaxLeft = 0
Dim ws As Worksheet
Set ws = Worksheets("HR")

MonthlyAverageLeft =      Application.WorksheetFunction.AverageIf(ws.Range("B:B"), "<>",     ws.Range("I:I"))
MonthlyMinLeft = Application.WorksheetFunction.MinIfs(ws.Range("I:I"), ws.Range("B:B"), "<>")
MonthlyMaxLeft = Application.WorksheetFunction.MaxIfs(ws.Range("I:I"), ws.Range("B:B"), "<>")
MonthlyMedianLeft = 

Worksheets("HR Survey Summary").Activate
Cells(13, 7) = MonthlyAverageLeft
Cells(15, 7) = MonthlyMinLeft
Cells(16, 7) = MonthlyMaxLeft

'''

Aucun commentaire:

Enregistrer un commentaire