|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 34682189 于 2024-2-3 15:55 编辑
'返回表达式的值
Public Function JS(jss, Optional xs As Variant)
Dim jsz
If Len(jss) = 0 Then JS = "": Exit Function
jss = Replace(jss, "{", "(")
jss = Replace(jss, "}", ")")
Do
If UBound(Split(jss, "[")) <> UBound(Split(jss, "]")) Then JS = "括号错误": Exit Function
If InStr(jss, "[") > InStr(jss, "]") Then JS = "括号错误": Exit Function
If InStr(jss, "[") = 0 Then Exit Do
jss = Left(jss, InStr(jss, "[") - 1) & Right(jss, Len(jss) - InStr(jss, "]"))
If InStr(jss, "]") = 0 Then Exit Do
Loop
If Left(jss, 1) = "=" Then
Do Until Left(jss, 1) <> "="
jss = Mid(jss, 2)
Loop
End If
On Error GoTo ERR001
If Len(jss) = 0 Then JS = "": Exit Function
If Len(jss) > 254 Then JS = "公式超长": Exit Function
If IsMissing(xs) Or IsNumeric(xs) = True Then
jsz = Evaluate("=" & jss)
If IsNumeric(xs) = True Then
jsz = IIf(Int(Abs(xs)) < 9, Round(jsz, Int(Abs(xs))), Round(jsz, 9))
End If
JS = IIf(IsNumeric(jsz) = True, jsz, "公式错误")
ElseIf UCase(xs) = "GS" Then
JS = jss
Else
GoTo ERR001
End If
Exit Function
ERR001:
JS = "公式错误"
End Function |
|