1楼LENGMA()的原代码是:Function LENGMA(rng As Range) As StringDim ss1 As String, ss2 As String, s1 As String, s2 As String, ar
If rng.Count > 1 Then
ar = rng
If ar(UBound(ar), 1) <> "" Then
s1 = Mid(ar(UBound(ar), 1), 1, 1)
s2 = Mid(ar(UBound(ar), 1), 2, 1)
For i = UBound(ar) - 1 To 1 Step -1
If ss1 = "" And Mid(ar(i, 1), 1, 1) <> s1 Then ss1 = Mid(ar(i, 1), 1, 1)
If ss2 = "" And Mid(ar(i, 1), 2, 1) <> s2 Then ss2 = Mid(ar(i, 1), 2, 1)
If ss1 <> "" And ss2 <> "" Then Exit For
Next
If ss1 <> "" And ss2 <> "" Then LENGMA = 3 - s1 - ss1 & 3 - s2 - ss2
End If
End If
End Function
而4楼D列公式的代码是:
Function f(r1, r2, s)
t11 = Left(r1, 1): t12 = Right(r1, 1)
t21 = Left(r2, 1): t22 = Right(r2, 1)
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
f = s1 & s2
End Function
如果E5输入综合公式:=IF(ROW()<15,LENGMA(B$5:B5),f(B4,B5,E4)),就能既保证了计算结果的正确,又极大地提升了运算速度!
我在想,怎样才能把上面的两个代码合二为一?恳请老师们帮忙解决!
|