VBA操作Excel类模块的综合运用:
Public 条件
Private rngs
Private n
Dim cc
Property Set 单元格(rng As Range)
If rng > 条件 Then
n = n + 1
If n = 1 Then Set rngs = rng
Set rngs = Union(rngs, rng)
End If
cc = rngs.Address
End Property
Function 求和()
求和 = WorksheetFunction.Sum(rngs)
End Function
Function 最大值()
最大值 = WorksheetFunction.Max(rngs)
End Function
Function 最小值()
最小值 = WorksheetFunction.Min(rngs)
End Function
Function 平均值()
平均值 = WorksheetFunction.Average(rngs)
End Function
Function 极大值(k As Integer)
极大值 = WorksheetFunction.Large(rngs, k)
End Function
Function 极小值(k As Integer)
极小值 = WorksheetFunction.Small(rngs, k)
End Function
类模块调用:
Sub test()
Dim dd As New 类1
For Each rn In [a1:a9]
dd.条件 = 4
Set dd.单元格 = rn
Next
MsgBox dd.极小值(3)
End Sub