Reputation: 13
Today is my first day writing Excel macro and I was given a task to modify someone else's' code to add new features. I learn Excel has a Immediate window which I am finding very useful.
I do have a question that I am unable to find the answer to in the last hour of searching. If you look at the image below you will notice that fstr
is a string variable.
Currently, fstr
holds a formula. How can I print out actual value of this formula instead of the formula itself?
One thing I tried was fstr.xlPastValues
, but it didn't work. I got this idea from recording a macro while pasting a value of a formula manually.
Upvotes: 1
Views: 3234
Reputation: 166735
You can use the Evaluate method:
Sub Tester()
Dim sFormula As String
sFormula = "=A1+A2"
'evaluate in the context of the current worksheet
' adjust to suit...
Debug.Print ActiveSheet.Evaluate(sFormula)
End Sub
Upvotes: 4