|
Function JG(JSS, Optional x) '返回计算公式的值或值的计算公式
Dim S%, E%
Dim JS As String
If JSS = "" Then
JG = ""
Else
If IsMissing(x) Then '返回计算公式的值
If Left(JSS, 1) = "=" Then
JSS = Mid(JSS, 2)
End If
Do Until InStr(1, JSS, "[") = 0
S = InStr(1, JSS, "[")
E = InStr(1, JSS, "]")
JSS = Left(JSS, S - 1) & Mid(JSS, E + 1)
Loop
JG = Evaluate("=" & JSS)
ElseIf x = 2 Then '返回值的计算公式或可计算的表达式或值本身
If JSS.HasFormula = True Then
JG = Mid(JSS.Formula, 2)
Else
If IsNumeric(Evaluate(JSS.Value)) = True Then
JG = JSS.Value
Else
JS = JSS.Value
Do Until InStr(1, JSS, "[") = 0
S = InStr(1, JSS, "[")
E = InStr(1, JSS, "]")
JSS = Left(JSS, S - 1) & Mid(JSS, E + 1)
Loop
If IsNumeric(JSS) = True Or IsNumeric(Evaluate(JSS)) = True Then
JG = JS
End If
End If
End If
End If
End If
End Function |
|