使用 vba 计算中位数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23311008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:54:04  来源:igfitidea点击:

Calculate median using vba

excelexcel-vbavba

提问by richie

How do I calculate the median for a range of more than 30 values using VBA? The WorkSheetFormulamethod can handle only 30 values. My function at the moment looks like this;

如何使用 VBA 计算超过 30 个值的范围的中位数?该WorkSheetFormula方法只能处理 30 个值。我现在的功能是这样的;

Function medval(Longitudes As Range)
'I want the median for values in the range (here 'Longitudes') B2:B100)
End Function

回答by Mitch Wheat

You can average/find median of as many contiguous data values as you want:

您可以根据需要平均/查找任意数量的连续数据值的中位数:

=MEDIAN(A1:A65500)will work

=MEDIAN(A1:A65500)将工作

but you cannot exceed 30 individual references in Excel 2003 (in 2007 you can have 255 references).

但在 Excel 2003 中您不能超过 30 个单独的引用(在 2007 年您可以有 255 个引用)。

i.e.

IE

=MEDIAN(A1,A2,A3,...A31)will not work.

=MEDIAN(A1,A2,A3,...A31)不管用。

A range of values will work as long as they are contiguous

一系列值只要它们是连续的就可以工作