简体   繁体   English

计算多列的中位数

[英]Calculate median of multiple columns

In my worksheet, named "Sheet1", Column A through Column J, each column contains various values (so they all have different number of rows). 在名为“ Sheet1”的工作表中,从A列到J列,每列都包含各种值(因此它们的行数都不同)。

How to calculate median of these columns and put the calculated median in row9, and columns M through V? 如何计算这些列的中位数并将计算的中位数放入第9行以及M至V列?
I known how to store the calculated median into desired location but really not sure how to calculate median. 我知道如何将计算出的中位数存储到所需位置,但真的不确定如何计算中位数。

I know this can be solved just by using excel median function, but this is not what I am trying to do. 我知道这可以通过使用excel中值函数来解决,但这不是我要尝试的方法。 I have over 10+worksheets, so a VBA would be the most efficient. 我有10多个工作表,所以VBA是最有效的。

All you need is to set M9 =MEDIAN(A2:A8) and have the A2:A8 set to the range you want. 您需要设置M9 = MEDIAN(A2:A8)并将A2:A8设置为所需范围。

Then just copy and paste that over to the other columns M9:V9. 然后,只需将其复制并粘贴到其他列M9:V9中即可。 Excel will auto-change the columns to B,C,D, etc, and will fill in the info you want. Excel将自动将列更改为B,C,D等,并填写所需的信息。

Edit for VBA: 编辑 VBA:

Here is a quick and dirty VBA macro to apply them all: 这是一个快速而肮脏的VBA宏,可以将它们全部应用:

Sub StacvQ()

    For SheetIndex = 1 To Sheets.Count
        Sheets(SheetIndex).Select
        Cells(9, 13).FormulaR1C1 = "=Median(R2C[-12]" & ":" & "R8C[-12])"
        Cells(9, 13).Copy
        Range(Cells(9, 13), Cells(9, 22)).Select
        ActiveSheet.Paste

    Next SheetIndex

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM