【发布时间】:2018-07-06 18:51:54
【问题描述】:
我对此很陌生,所以我在处理这段代码时遇到了一些问题,希望能得到一些帮助。目标是在满足另一个范围2(即文本)的标准时对过滤/可见单元格的范围进行平均。
到目前为止,我有以下内容:
Function AverVisibleIC(Rg As Range, BU As Range)
Dim xCell As Range
Dim xCount As Integer
Dim xTtl As Double
Dim c As Range
Set BU = Range("B13:B44")
Application.Volatile
Set Rg = Intersect(Rg.Parent.UsedRange, Rg)
For Each xCell In Rg
If xCell.ColumnWidth > 0 _
And xCell.RowHeight > 0 _
And Not IsEmpty(xCell) _
And IsNumeric(xCell.Value) Then
xTtl = xTtl + xCell.Value
xCount = xCount + 1
End If
Next
If xCount > 0 Then
For Each c In BU
If c.Value = "IC" Then
AverVisibleIC = xTtl / xCount
Else
AverVisibleIC = 0
End If
End If
Next
End Function
谢谢!
【问题讨论】:
-
所用范围的行和列是否都为零宽度/高度?
-
为什么你将BU作为范围参数传入,然后将其重置为
Set BU = Range("B13:B44")而不使用它?