VBA Change Chart Title

FifthJ4ck 4

New Member
Joined
Jun 9, 2017
Messages
2
I have seen a lot of similar questions but nothing that is quite the same as what I am trying to do. I am trying to modify Data Labels in a chart tab, which was copied from another chart. I already have a macro that changes the data and the chart title but now I want to change data labels of which there are which there are only a few and they apply to specific points in a large set of data. The text in the data label is referenced from a cell in a sheet. When I copy the chart it keeps the old reference from the old sheet, I am just trying to change that reference based on the associated sheet name.
Here is my current code so far:

Sub Changedatapoints()
''' Just do active chart
If ActiveChart Is Nothing Then
'' There is no active chart
MsgBox "Please select a chart and try again.", vbExclamation, _
"No Chart Selected"
Exit Sub
End If


Dim OldString As String, NewString As String, strTemp As String
Dim mySrs As Object


OldString = InputBox("Enter the string to be replaced:", "Enter old string")


If Len(OldString) > 1 Then
NewString = InputBox("Enter the string to replace " & """" _
& OldString & """:", "Enter new string")
'' Loop through all series
mySrts.HasDataLabels = True
For Each DataLabel In ActiveChart
strTemp = WorksheetFunction.Substitute(ActiveChart.DataLabels.Formula, OldString, NewString)
mySrs.Formula = strTemp
Next
Else
MsgBox "Nothing to be replaced.", vbInformation, "Nothing Entered"
End If
End Sub




Currently the compiler is saying "Method or data member not found" about the first line. Also the labels are in the same cells in each sheet. And all I want to do have to do is type in the old sheet name, press enter, then type the new sheet name, press enter and be done.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top