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.
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.