|
楼主 |
发表于 2019-7-5 22:11
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 WYS67 于 2019-7-5 22:26 编辑
老师:真是不好意思,还得麻烦您给33楼的代码增加一个判断语句:表二《有问题》E F G列粉红色填充所示:D列是第五参数指定次序,E列公式 { =DTJCX($A$5:$A$100000,$E$3,$B$5:$B$100000,E$4,$D5:$D40) 计算出的符合条件的数据个数如辅助列C列所示,只有29个,小于第五参数指定次序$D5:$D40的36个,所以就会出现粉红色填充显示的错误结果【如果符合条件的数据个数,等于或大于$D5:$D40的36个则可以显示正确结果】。
正确的结果是:1.F5:F33显示如G5:G33;2.而E34:G40由于已没有符合条件的数据,则应该显示为空白!
总是无法上传附件,代码如下:
Function DTJCX(aa As Range, a, ab As Range, b, ac As Range, Optional u, Optional v = "")
'Application.Volatile
Dim ar, br, cr, dr, er, fr, gr, hr, rr, R, s, t, i&, j&, k&, n&
ar = aa: br = ab: cr = ac: s = a: t = b
ReDim dr(1 To UBound(ar), 0), er(1 To UBound(ar), 0), fr(1 To UBound(ar), 0)
For k = UBound(ar) To 1 Step -1
If ar(k, 1) <> "" Then Exit For
Next
For i = 1 To k
If ar(i, 1) <> "" And br(i, 1) <> "" And ar(i, 1) = s Then
n = n + 1: dr(n, 0) = br(i, 1)
End If
Next
If IsArray(cr) Then
If t = 0 Then
For i = 1 To UBound(ar)
If cr(1, 1) < cr(UBound(cr), 1) Then y = i Else y = UBound(cr) - i + 1
If i <= UBound(cr) Then er(i, 0) = dr(y, 0) Else er(i, 0) = ""
Next
Else
For i = 1 To UBound(ar)
If cr(1, 1) < cr(UBound(cr), 1) Then y = i Else y = UBound(cr) - i + 1
If i <= UBound(cr) Then er(i, 0) = dr(n - y + 1, 0) Else er(i, 0) = ""
Next
End If
Else
If t = 0 Then R = dr(cr, 0) Else R = dr(n - cr + 1, 0)
If cr = "" Then R = ""
End If
If v = "" Then
If IsArray(cr) Then DTJCX = er Else DTJCX = R
Else
hr = u: ReDim gr(0 To UBound(hr)): gr(0) = 0
For i = 1 To UBound(hr): gr(i) = hr(i, 1): Next
If IsArray(cr) Then
For i = 1 To UBound(ar)
If i <= UBound(cr) Then
For j = UBound(gr) To 1 Step -1
If er(i, 0) > gr(j - 1) And er(i, 0) <= gr(j) Then
If v = 1 Then fr(i, 0) = j - 1 Else fr(i, 0) = gr(j) - er(i, 0)
End If
Next
Else
fr(i, 0) = ""
End If
Next
DTJCX = fr
Else
If R = "" Then
rr = ""
Else
For j = UBound(gr) To 1 Step -1
If R > gr(j - 1) And R <= gr(j) Then
If v = 1 Then rr = j - 1 Else rr = gr(j) - R
End If
Next
End If
DTJCX = rr
End If
End If
End Function
|
|