标签:
vbaexcel计算式注释计算结果含注释计算式 |
分类: 我爱电脑 |
以前也解决过这样的问题,但相对简单,就是利用引用ACCESS数据库里面的eval_r()函数来处理,但那个方法有个缺点,可移值性太差,如果考到另一台机子上,而这台机子没装ACCESS的话就会出错。
以下代码解决上面的所有问题:
Function js(x)
On Error Resume Next
temp = x
If temp Like "*]*" Then
DoorID = 0
string_length = Len(temp)
For i = 1 To string_length
string_temp = Mid(temp, i, 1)
If string_temp = "[" Then DoorID = 1
If string_temp = "]" Then DoorID = 0
If DoorID = 1 Then
If i = 1 Then
temp = " " + Right(temp, string_length - i)
Else
temp = Left(temp, i - 1) + " " + Right(temp, string_length -
i)
End If
End If
Next i
temp = Application.Substitute(temp, "]", "")
temp = Application.Substitute(temp, " ", "")
End If
js = Evaluate(temp)
On Error GoTo 0
End Function
js = Evaluate(temp)
End Function
好了,这样就可以在计算式中实现注释啦,如
js([张三的钱]50[就这么多]+[李四的钱]30[就这么少])=80,这样数字再长也不愁忘记啦。