|
楼主 |
发表于 2018-6-18 19:22
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 13782671637 于 2018-6-18 19:25 编辑
老师:是不是代码无法计算文本类数字?为什么下面蓝桥玄霜版主的代码能显示正确结果呢?Sub 冷码1()
Dim brr(), sr()
tms = Timer
m = [c2].Value - 4
ar = [b5].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
If ar(i - 1, 1) <> "" Then t = ar(i - 1, 1): t11 = Left(t, 1): t12 = Right(t, 1)
If ar(i, 1) <> "" Then
t = ar(i, 1): t21 = Left(t, 1): t22 = Right(t, 1)
If t11 = t21 Then s1 = Left(s, 1) Else s1 = 3 - Val(t11) - Val(t21)
If t12 = t22 Then s2 = Right(s, 1) Else s2 = 3 - Val(t12) - Val(t22)
s = s1 & s2
sr(i, 1) = s
End If
Next
[c5].Resize(m) = sr
MsgBox Format(Timer - tms, "0.000s")
End Sub
|
|