|
本帖最后由 YZC51 于 2018-6-24 10:22 编辑
请参考
Sub Zopey()
Dim brr(), sr()
n = [C2]
If Len([Q10]) = 0 Then x1 = UCase(InputBox("请输入数据列名称")): [Q10] = x1: x = Asc(x1) - 64 Else x = Asc([Q10]) - 64
If Len([S10]) = 0 Then y1 = UCase(InputBox("请输入输出列名称")): [S10] = y1: y = Asc(y1) - 64 Else y = Asc([S10]) - 64
If Len(n) = 0 Then n = InputBox("请输入数据最大行"): [C2] = n
Z = 5
' m = Cells(Rows.Count, 1).End(3).Row - 4
m = Cells(n, x).End(3).Row - 4
If m < 5 Then m = n - 4
Cells(n, y).Resize(m) = ""
MsgBox "开始计算..."
tms = Timer
Columns(y).NumberFormatLocal = "@"
m = Cells(Rows.Count, x).End(3).Row - Z + 1
Cells(Z, y).Resize(100) = ""
ar = Cells(Z, x).Resize(m)
ReDim sr(1 To m, 1 To 1)
ReDim brr(0 To 2)
For I = 1 To m
t = ar(I, 1): t1 = Left(t, 1)
brr(t1) = brr(t1) + 1: If brr(t1) = 1 Then k1 = k1 + 1
If k1 = 2 Then k1 = I: Exit For
Next
s1 = 3 - Left(ar(1, 1), 1) - Left(ar(k1, 1), 1)
ReDim brr(0 To 2)
For I = 1 To m
t = ar(I, 1): t2 = Right(t, 1)
brr(t2) = brr(t2) + 1: If brr(t2) = 1 Then k2 = k2 + 1
If k2 = 2 Then k2 = I: Exit For
Next
s2 = 3 - Right(ar(1, 1), 1) - Right(ar(k2, 1), 1)
s = s1 & s2
If k1 > k2 Then k0 = k1 Else k0 = k2
For I = k0 To m
t = ar(I - 1, 1): t11 = Left(t, 1): t12 = Right(t, 1)
t = ar(I, 1): t21 = Left(t, 1): t22 = Right(t, 1)
On Error GoTo JS
If t11 = t21 Then s1 = Left(s, 1) Else s1 = 3 - t11 - t21
If t12 = t22 Then s2 = Right(s, 1) Else s2 = 3 - t12 - t22
s = s1 & s2
sr(I, 1) = s
Next
JS:
Cells(Z, y).Resize(m - 1) = sr
MsgBox Format(Timer - tms, "0.000s")
End Sub
|
|