|
楼主 |
发表于 2018-12-20 15:39
|
显示全部楼层
附: 原代码
Function SSLJ(rn As Range, a, Optional b = "")
Dim ar, br, cr, dr, c%, d&, i&, j&, m&, n&, x&, y&
Application.Volatile
ar = rn: x = Application.Count(rn)
c = (x - 2) Mod 3: d = Int(x / 3)
For j = UBound(ar) To 1 Step -1
If ar(j, 1) <> "" Then Exit For
Next
ReDim br(1 To j, 0): ReDim cr(1 To UBound(ar), 0): ReDim dr(1 To UBound(ar), 0)
For i = 1 To j
If ar(i, 1) <> "" Then y = y + 1: br(y, 0) = ar(i, 1)
Next
For i = 1 To UBound(ar)
m = i * 3 + c
If i < d Then cr(i, 0) = br(m - 2, 0) & br(m - 1, 0) & br(m, 0) Else: cr(i, 0) = ""
If b <> 0 And b <> "" Then
n = b - d - 3
If i > n And i < b - 3 Then dr(i, 0) = cr(i - n, 0) Else: dr(i, 0) = ""
End If
Next
If a = 1 And (b = 0 Or b = "") Then cr(d, 0) = br(x - 1, 0) & br(x, 0)
If a = 1 And b <> 0 And b <> "" Then dr(b - 3, 0) = br(x - 1, 0) & br(x, 0)
If b = 0 Or b = "" Then SSLJ = cr
If b <> 0 And b <> "" Then SSLJ = dr
End Function
此代码,当E:H列输入完整公式 {=SSLJ(数据区域,连接模式【0或1】,显示位置【0或指定行号】) 时,当A列数据个数除以3的余数为0或1时,显示的计算结果都非常正确;但余数为2时,就会出现如下所示的最后一个三位数被遗漏,而没有显示的错误。如下面三个截图所示
麻烦老师们看看是代码的哪一步计算出现的错误,并给予改正。下面是附件:
多条件连接A列数据.zip (52.99 KB, 下载次数: 0)
|
|