BENSON
01-10-2014, 08:43 PM
I have a sub button that when clicked adds a trend line to my graph. The code below adds the trend line and edits the text on the button to say "Remove trend line".I need help adding the 2nd code below to the button so when clicked again it removes the trend line and edits the text on the button back to "Add text Line"
Sub Button116_Click()
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Trendlines.Add(Type:=xlLogarithmic, Forward _
:=0, Backward:=0, DisplayEquation:=False, DisplayRSquared:=False).Select
ActiveChart.SeriesCollection(1).Trendlines(1).Select
With Selection.Border
.ColorIndex = 5
.Weight = xlThick
.LineStyle = xlContinuous
ActiveSheet.Shapes("Button 116").TextFrame _
.Characters.Text = "REMOVE TREND LINE"
End With
End Sub
2nd piece of code
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Trendlines(1).Select
Selection.Delete
ActiveSheet.Shapes("Button 116").TextFrame _
.Characters.Text = "ADD TREND LINE"
Sub Button116_Click()
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Trendlines.Add(Type:=xlLogarithmic, Forward _
:=0, Backward:=0, DisplayEquation:=False, DisplayRSquared:=False).Select
ActiveChart.SeriesCollection(1).Trendlines(1).Select
With Selection.Border
.ColorIndex = 5
.Weight = xlThick
.LineStyle = xlContinuous
ActiveSheet.Shapes("Button 116").TextFrame _
.Characters.Text = "REMOVE TREND LINE"
End With
End Sub
2nd piece of code
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Trendlines(1).Select
Selection.Delete
ActiveSheet.Shapes("Button 116").TextFrame _
.Characters.Text = "ADD TREND LINE"