|
本帖最后由 yy6831817 于 2021-5-21 11:25 编辑
求助如何添加判断,加快运算,(存在问题:在输入<>内容时,如果没在K列找到相同字符时,运行很卡,是否可以添加判断,加快运算,或其他办法)求大老出手。。。。谢谢
'自定义公式StringValue(h5)
Public Function StringValue(irng As Range)
Application.Volatile
Dim s$, i, tmp$, tmp1$, ichr$, iAsc%, iChrA$
iChrA = "()+-*/!^%0123456789."
s = Replace(Replace(Replace(irng.Formula, "÷", "/"), "×", "*"), "π", 3.1415926)
With CreateObject("vbscript.regexp")
.Pattern = "<.+?>" 【如何添加判断如在K列中没有找到 "<.+?>" 相同文体,就结束运算(结束函数 )】
.Global = True
If .test(s) Then
Set mh = .Execute(s)
For Each m In mh
s = th(s, m.Value)
Next m
End If
.Pattern = "\[[^\[\]]*\]|[一-龥]+"
s = .Replace(s, "")
End With
StringValue = Application.Evaluate(s)
End Function
'计算公式中码K列代码=G列数值
Function th(s, str1)
th = s
For j = 4 To Cells(Rows.Count, "k").Row
If Cells(j, "k") = str1 Then
th = Replace(s, str1, Cells(j, "g"))
Exit For
End If
Next j
End Function
|
|