我正在编写一个宏公共函数,用于查找冬季(11月,12月,1月,2月)的最后N
个非空单元格的最大值。
这就是我得到的:
Public Function SuperMax_Winter(rng2 As Range, rng As Range, N As Long) As Double
Dim RngCnt, RngCnt2 As Long, i As Long, Zum As Double, j As Long
Dim ary() As Double
ReDim ary(0)
j = 0
RngCnt = rng.Count
RngCnt2 = rng2.Count
If RngCnt <> RngCnt2 Then SuperMax_Winter = "#ERROR!"
For i = RngCnt To 1 Step -1
If rng(i).Value <> "" Then
If rng2(i).Month = 11 Or rng2(i).Month = 12 Or rng2(i).Month = 1 Or rng2(i).Month = 2 Then
ary(j) = rng(i).Value
If j = N - 1 Then Exit For
ReDim Preserve ary(j + 1)
j = j + 1
End If
End If
Next i
SuperMax_Winter = Application.WorksheetFunction.Max(ary)
End Function
但是出现#VALUE!
错误。
答案 0 :(得分:1)
我认为应该以月为准
If Month(rng2(i).Value)= 11 Or Month(rng2(i).Value)= 12 Or Month(rng2(i).Value)= 1 Or Month(rng2(i).Value)= 2 Then
希望获得帮助。