Assuming that you'll get a string BoolOperator1
that is a valid operator, e.g. >=
, =
, and a numeric value NumericValue1
, the easiest way to execute this comparison on another numeric value ValueToCompare
is to use the Evaluate
function. This will execute a string as VBA and return it's result.
In your case, you could simply use:
If Evaluate(ValueToCompare&BoolOperator1&NumericValue1) Then ...
If you want to use this in a Select Case
statement, you'd either need to use a simple If ... ElseIf ...
statement - or use this trick:
Select Case True
Case Evaluate(ValueToCompare&BoolOperator1&NumericValue1): ...
Case Evaluate(ValueToCompare&BoolOperator2&NumericValue2): ...
Case Else ...
End Select