Good Morning
I have a textbox on a chart which acts as a legend for the chart. Upon updating the data, the legend needs to be updated as well.
I have all the code to access the text box. The problem I'm having is replacing the text in the text box with the new string of text.
The bolded line above is where it fails. That line was recorded from a macro where i added some text to a textbox so I'm not sure why it isn't working. My guess is that line might only enable 1 character?
I have a textbox on a chart which acts as a legend for the chart. Upon updating the data, the legend needs to be updated as well.
I have all the code to access the text box. The problem I'm having is replacing the text in the text box with the new string of text.
Code:
Sub AddTextBoxtoChart()
Dim objChart As Chart, strTemp As String, cCell As Range
Dim objTextBox As Shape, strTBName As String
With Sheets("P&LChart")
Set objChart = ActiveChart
End With
strTemp = ""
With objChart
' add the code to delete the existing text box here or just replace the text?
Set objTextBox = .Shapes.AddTextbox(msoTextOrientationHorizontal, 79.5, 43.5, 141.5, 57.8)
objTextBox.Name = "PLChartLegend"
For Each cCell In Sheets("ChartData").Range("$X$2:$X$11")
strTemp = strTemp & " " & cCell.Value & " " & Round((cCell.Offset(0, 1).Value * 100), 1) & " %" & vbCrLf
'Debug.Print strTemp
Next cCell
[B]objTextBox.ShapeRange(1).TextFrame2.TextRange.Characters.Text = strTemp[/B]
'Debug.Print strTemp
End With
End Sub
The bolded line above is where it fails. That line was recorded from a macro where i added some text to a textbox so I'm not sure why it isn't working. My guess is that line might only enable 1 character?