|
楼主 |
发表于 2019-7-6 17:44
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 WYS67 于 2019-7-7 08:30 编辑
老师:33楼的代码--当符合条件的数据个数,少于第五参数指定次序的单元格个数时,所以就会出现粉红色填充显示的错误结果【如果符合条件的数据个数,等于或大于第五参数指定次序的单元格个数,则可以显示正确结果】。
正确的结果是:第五参数指定次序的单元格区域内,如果没有符合条件的数据,则应该显示为空白。
麻烦您修改相关代码。
如《总表》第五参数指定次序是K5:K31【共27个单元格】,而符合条件的数据只有17个,所以显示#VALUE!错误;《有问题》里第五参数指定次序是D5:D40【共36个单元格】,而符合条件的数据只有29个,所以E34:E40显示错误的“0”,F5:F40显示#VALUE!,G34:G40显示#VALUE!
遗漏分区和剩余期数 (1).zip
(618.47 KB, 下载次数: 20)
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
|
|