|
楼主 |
发表于 2014-7-10 10:03
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Evaluate可以计算超过255字符的计算式.zip
(28.62 KB, 下载次数: 347)
工程量计算式超过255,也不用担心,完全可以计算,欢迎使用- '自动计算
- Function tn(R As String, Optional n As Variant) As Variant
- Dim PL As String, PR As String, PL2 As String, PR2 As String
- If IsMissing(n) Then Else If n <> Int(n) Or n < 0 Then GoTo a4
- Do
- If InStr(R, "[") > InStr(R, "]") Then GoTo a4
- If InStr(R, "[") = 0 Then Exit Do
- PL = Left(R, InStr(R, "]") - 1)
- PR = Right(R, Len(R) - InStr(R, "]"))
- PL2 = Left(PL, InStrRev(PL, "[") - 1)
- R = PL2 & PR
- If InStr(R, "]") = 0 Then Exit Do
- Loop
- R = StrConv(R, vbNarrow)
- R = Replace(R, "K", "^(.5)")
- R = Replace(R, "F", "^(2)")
- R = Replace(R, "÷", "/")
- R = Replace(R, "×", "*")
- If Len(R) > 255 Then GoTo a1
- Zhuhanshu:
- On Error GoTo a4
- If IsMissing(n) Then
- tn = Round(Evaluate(R), 3)
- Else
- tn = Round(Evaluate(R), n)
- End If
- Exit Function
- If 1 = 2 Then
- a1:
- On Error GoTo a4
- If InStr(R, "(") = 0 Then GoTo a2
- Do
- PL = Left(R, InStr(R, ")") - 1)
- PR = Right(R, Len(R) - InStr(R, ")"))
- If IsNumeric(Left(PR, 1)) Or Left(PR, 1) = "(" Or Left(PR, 1) = "." Then GoTo a4
- PL2 = Left(PL, InStrRev(PL, "(") - 1)
- PR2 = Right(PL, Len(PL) - InStrRev(PL, "("))
- R = PL2 & Evaluate(PR2) & PR
- If Len(R) <= 255 Then GoTo Zhuhanshu
- If InStr(R, "(") = 0 Then GoTo a2
- Loop
- End If
- If 1 = 2 Then '无()时
- a2:
- On Error GoTo a4
- If InStr(R, "+") = 0 And InStr(R, "-") = 0 Then GoTo a3
- Do
- PL = Left(R, 255)
- If InStrRev(PL, "+") > InStrRev(PL, "-") Then
- PL2 = Left(PL, InStrRev(PL, "+") - 1)
- R = Evaluate(PL2) & Right(R, Len(R) - InStrRev(PL, "+") + 1)
- Else
- PL2 = Left(PL, InStrRev(PL, "-") - 1)
- R = Evaluate(PL2) & Right(R, Len(R) - InStrRev(PL, "-") + 1)
- End If
- If Len(R) <= 255 Then GoTo Zhuhanshu
- If InStr(R, "+") = 0 And InStr(R, "-") = 0 Then GoTo a3
- Loop
- End If
- If 1 = 2 Then
- a3:
- On Error GoTo a4
- Do
- PL = Left(R, 255)
- If InStrRev(PL, "*") > InStrRev(PL, "/") Then
- PL2 = Left(PL, InStrRev(PL, "*") - 1)
- R = Evaluate(PL2) & Right(R, Len(R) - InStrRev(PL, "*") + 1)
- Else
- PL2 = Left(PL, InStrRev(PL, "/") - 1)
- R = Evaluate(PL2) & Right(R, Len(R) - InStrRev(PL, "/") + 1)
- End If
- If Len(R) <= 255 Then GoTo Zhuhanshu
- Loop
- End If
- If 1 = 2 Then
- a4:
- If R = "" Then tn = "" Else tn = "错误"
- If R = "密码" Then tn = "不能让你看"
- End If
- End Function
复制代码 |
|