Home » excel » vba – Put a formula in excel chart

vba – Put a formula in excel chart

Posted by: admin April 23, 2020 Leave a comment

Questions:

I want to fill a text box on an Excel chart using VBA. I tried this:

 ActiveSheet.ChartObjects("Chart 1").Chart.Shapes(1).Formula = "Sheet1!A1"

and it doesn’t work, but this does:

 ActiveSheet.ChartObjects("Chart 1").Chart.Shapes(1).Select
 Selection.Formula = "=Sheet1!A1"

There probably is something I need to put between Shapes(1) and .Formula, but I can’t find it. Any suggestions?

How to&Answers:

Note that the second formula (the one that works) includes an equals sign before the sheet name:

“=Sheet1!A1”

while the first does not:

“Sheet1!A1”