【发布时间】:2017-02-02 00:58:16
【问题描述】:
我想计算加权平均值和加权标准差。我能够计算平均值但不能计算标准偏差。我该怎么办?
With Application.WorksheetFunction
Range("AH" & 2) = .SumProduct(Columns(7), Columns(8)) / .Max(Columns(8)) 'This code works very well. It calculates the mean
Dim Nprime As Double
Nprime = .CountIf(Range("H2:H" & lengthRows), "<>" & 0) 'This code works well
Range("AM" & 2) = 2 * .SQRT(.SumProduct((Columns(7) - Columns(34)) ^ 2, Columns(8)) / ((Nprime - 1) * .Sum(Columns(8))) / Nprime) 'This line does not work. It should calculate the weighted standard deviation.
Range("AM" & 2) = Evaluate("2*SQRT(SumProduct((Columns(7) - weightedMean)^2), Columns(8)) / ((Nprime - 1) * .Sum(Columns(8))) / Nprime)") 'This line code evaluates with an answer of #VALUE! probably due to the titles in Row1, how do I fix the code to only evaluate the numerical values within the columns?
End With
【问题讨论】:
-
你想在
Range("AL:AL") = Columns(7)中做什么? -
我试图弄清楚为什么 std dev 计算不起作用。您可以忽略该行
-
老实说,我不确定如何解决这个问题,您应该考虑将范围实例化为对象,因为
Column(7)不可读,您必须记住该范围内的内容,而第三方只是无法弄清楚这是什么。 -
没关系。谢谢你的帮助。我最终会通过调用一个函数来以不同的方式执行此操作。