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.
 

Forum statistics

Threads
1,081,528
Messages
5,359,305
Members
400,524
Latest member
Excelbat

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top