I need to evaluate a VBA expression in VBA, which sounds easy but I cannot figure it out...
Test1 is how I want it to work, I want the Msgbox to display 2 like it does in the Test2-macro.
I haven't got any versions of Evaluate to work, Application.Evaluate, ActiveSheet.Evaluate or Evaluate(CStr(Eq))
Any creative solutions?
Test1 is how I want it to work, I want the Msgbox to display 2 like it does in the Test2-macro.
I haven't got any versions of Evaluate to work, Application.Evaluate, ActiveSheet.Evaluate or Evaluate(CStr(Eq))
Code:
Sub Test1()
Dim Eq As String, Ary1 As Variant, Ans As Variant
Ary1 = Array(3, 6, 9)
Eq = "Application.Match(6, Ary1, 0)"
Ans = Evaluate(Eq)
MsgBox Ans 'Ans is here = "Error 2029"
End Sub
Sub Test2()
Dim Ary1 As Variant, Ans As Variant
Ary1 = Array(3, 6, 9)
Ans = Application.Match(6, Ary1, 0)
MsgBox Ans 'Ans is here = 2
End Sub
Last edited by a moderator: