vba 用户定义函数中的用户定义运算符
vba user defined operator in user defined fuction
如何让用户可以定义运算符?例如,用户将键入
=iftrue(x+y,">=z",x+y) (much like a sumif or regular if function)
我知道我可以使用普通的 if 函数或使用单独的单元格来解决逻辑问题。然而,我这样做的原因是因为我有一个非常 cpu 密集的计算,必须重新计算而不是返回已经计算的值。
这是我目前拥有的。
Function iftrue(Value1, Criteria1, ValueifTrue)
' Function
If Value1 = Criteria1 Then
iftrue = ValueifTrue
Else: iftrue = Value1
End If
End Function
我猜你的代码的这个修改版本可以,试一试..
Function IfTrue(Value1, Criteria1, ValueifTrue)
'Function to Evaluate Calculation'
If Evaluate(Value1 & Criteria1) Then
IfTrue = ValueifTrue
Else
IfTrue = Value1
End If
End Function
这只是基本思路,您可能想在此基础上进行开发!
如何让用户可以定义运算符?例如,用户将键入
=iftrue(x+y,">=z",x+y) (much like a sumif or regular if function)
我知道我可以使用普通的 if 函数或使用单独的单元格来解决逻辑问题。然而,我这样做的原因是因为我有一个非常 cpu 密集的计算,必须重新计算而不是返回已经计算的值。
这是我目前拥有的。
Function iftrue(Value1, Criteria1, ValueifTrue)
' Function
If Value1 = Criteria1 Then
iftrue = ValueifTrue
Else: iftrue = Value1
End If
End Function
我猜你的代码的这个修改版本可以,试一试..
Function IfTrue(Value1, Criteria1, ValueifTrue)
'Function to Evaluate Calculation'
If Evaluate(Value1 & Criteria1) Then
IfTrue = ValueifTrue
Else
IfTrue = Value1
End If
End Function
这只是基本思路,您可能想在此基础上进行开发!