|
本帖最后由 玉阳山人 于 2018-9-7 05:18 编辑
下面两个代码,除了用红色标明的那一句外,其余完全一样。
第一个代码:
Public Function COUNTIFZQ2(qy As Range, zq, tj)
Application.Volatile
arr = qy
ReDim brr(1 To UBound(arr), 1 To 1) As Variant
j = 0
For i = 1 To UBound(arr)
brr(i, 1) = 0
Next
For i = 1 To UBound(arr)
If arr(i, 1) = "" Then Exit For
If (i Mod 36) = 1 Then j = j + 1
If arr(i, 1) = tj Then
brr(j, 1) = brr(j, 1) + 1
End If
Next
For i = j To UBound(arr)
brr(i, 1) = ""
Next
COUNTIFZQ2 = brr
End Function
第二个代码:
Public Function COUNTIFZQ2(qy As Range, zq, tj)
Application.Volatile
arr = qy
ReDim brr(1 To UBound(arr), 1 To 1) As Variant
j = 0
For i = 1 To UBound(arr)
brr(i, 1) = 0
Next
For i = 1 To UBound(arr)
If arr(i, 1) = "" Then Exit For
If (i Mod 36) = 1 Then j = j + 1
If arr(i, 1) = tj Then
brr(j, 1) = brr(j, 1) + 1
End If
Next
For i = j+1 To UBound(arr)
brr(i, 1) = ""
Next
COUNTIFZQ2 = brr
End Function
要求:在原先的区域数组公式 { =COUNTIFZQ(数据区域,指定周期,指定条件) 里增加用于判断选择的第四参数0或1,使公式变成:=COUNTIFZQ(数据区域,指定周期,指定条件,0【可省略】)或=COUNTIFZQ(数据区域,指定周期,指定条件,1)
这样,当输入公式为=COUNTIFZQ(数据区域,指定周期,指定条件,0【可省略】) 时,执行上面第一个代码的运算;而当输入公式为=COUNTIFZQ(数据区域,指定周期,指定条件,1) 时,则执行上面第二个代码的运算。
恳请老师们看看,应该怎样合并和修改上面的代码为好?
|
|