我已经设法通过编写这个宏来解决问题
'This works out how many rows (another way)
Dim AV As Long, AVC As Long
AV = Range("O" & Rows.Count).End(xlUp).Row
AVC = AV - 1
' This adds up all the data starting from row 2 to before the blank row
Dim LR As Long
myRange = ActiveSheet.Range("O2", Range("O2").End(xlDown))
LR = WorksheetFunction.sum(myRange)
'MsgBox LR
' So finding the mean
Dim mean As Long
Range("P2").Select
ActiveCell.FormulaR1C1 = LR / AVC
Selection.Value = Format(ActiveCell, "#.00")
,其在细胞P2中得到17.84的结果
但是当我试图写相同来计算标准偏差时,它返回的值为0.这是否意味着我不能使用下面的类似编码来完成这项工作?
' Doing stdev on range
Dim MD As Long
myRange = ActiveSheet.Range("O2", Range("O2").End(xlDown))
MD = WorksheetFunction.StDev_S(myRange)
MsgBox MD
另外,我无法弄清楚如何复制和粘贴它并根据O列中的行数停止。真的很感激一些帮助,因为我对编写宏非常陌生。
答案 0 :(得分:0)
将dim MD as Long
更改为dim MD as double
。