【发布时间】:2018-08-31 07:38:28
【问题描述】:
我想每 7 个单元格取一个单元格的平均值。例如,我想取单元格 A1、A8、A15、A22 等的平均值。然后再取 A2、A9、A16、A23 等的平均值。我有一个大数据集,我怎样才能快速做到这一点。
谢谢
【问题讨论】:
我想每 7 个单元格取一个单元格的平均值。例如,我想取单元格 A1、A8、A15、A22 等的平均值。然后再取 A2、A9、A16、A23 等的平均值。我有一个大数据集,我怎样才能快速做到这一点。
谢谢
【问题讨论】:
可能是用户定义的函数
Public Function Get7Average(ByVal rng As Range) As Variant
Dim arr(), i, total As Long, counter As Long
If rng.Columns.Count > 1 Or rng.Cells.Count < 7 Then
Get7Average = CVErr(xlErrNA)
Exit Function
Else
arr = rng.Value
For i = LBound(arr, 1) To UBound(arr, 1) Step 7
counter = counter + 1
If IsNumeric(arr(i, 1)) Then
total = total + arr(i, 1)
End If
Next
End If
If total = 0 Then
Get7Average = CVErr(xlErrNA)
Exit Function
End If
Get7Average = total / counter
End Function
在工作表中
【讨论】: