(Solved) – In Excel VBA, is there a way to pass a string as a condition for evaluation in an IF block?

(solved)-–-in-excel-vba,-is-there-a-way-to-pass-a-string-as-a-condition-for-evaluation-in-an-if-block?

In VBA, is there a way to create a function which receives one of it’s parameters as a string with a condition to be evaluated by an IF block?

This should give an idea of what I am looking for, but I now it’s not that simple:

Function StringAsCondition(a As String) As Boolean

    Dim result as Boolean
    Dim b As Long
    Dim c As Long

    b = 4
    c = 2    

    If a Then
        result = True
    End If

    StringAsCondition = result

End function



Sub Test()

    Dim a As String
    a = "b >= c"

    Dim functionresult As Boolean

    functionresult = StringAsCondition(a)

    MsgBox functionresult

End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *