vbanoobe
vbanoobe

Reputation: 13

vba user defined operator in user defined fuction

How do I make it so that the user can define the operator? For example the user will type

=iftrue(x+y,">=z",x+y) (much like a sumif or regular if function)

I understand I can use a normal if function or use a separate cell to solve for the logic. However the reason I am doing this is because I have a very cpu intensive computation that will have to recalculate rather than returning the already computed value.

This is currently what I have.

Function iftrue(Value1, Criteria1, ValueifTrue)

' Function

If Value1 = Criteria1 Then
iftrue = ValueifTrue

Else: iftrue = Value1

End If

End Function

Upvotes: 1

Views: 67

Answers (1)

PaulFrancis
PaulFrancis

Reputation: 5819

This modified versions of your code will do I guess, try it out..

Function IfTrue(Value1, Criteria1, ValueifTrue)
    'Function to Evaluate Calculation'

    If Evaluate(Value1 & Criteria1) Then
        IfTrue = ValueifTrue
    Else
        IfTrue = Value1
    End If

End Function

This is just the basic idea, you might want to develop on this !

Upvotes: 2

Related Questions