Deladier
Board Regular
- Joined
- May 4, 2005
- Messages
- 131
- Office Version
- 365
- Platform
- Windows
Hello.
I have a graph and using VBA I can change the order of that graph trend line but I have problems trying to change to polynomial type to linear type, apparently because of the order.
I believe, in the whole code, 'Order = tlgrade' code part shouldn't appear for a linear graph case. How can 'Order = tlgrade' dissapear (for linear trendline case) or appear (for polynomial trendline case) in the code structure?
Here is my code:
Sub Macro1()
Dim tlgrade As Integer, tltype As String
tlgrade = Range("B10").Value
ActiveSheet.ChartObjects("Graph 1").Activate
ActiveChart.SeriesCollection(1).Trendlines(1).Select
If tlgrade = 1 Then tltype = xlLinear
If tlgrade > 1 Then tltype = xlPolynomial
With Selection
.Type = tltype
.Order = tlgrade 'I think this part conditionally should appear or dissapear as the case
.Forward = 0
.Backward = 0
.InterceptIsAuto = True
.DisplayEquation = True
.DisplayRSquared = True
.NameIsAuto = True
End With
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "B10" Then
Macro1
End If
End Sub
How can I solve it?
Thanks in advance. Best regards
I have a graph and using VBA I can change the order of that graph trend line but I have problems trying to change to polynomial type to linear type, apparently because of the order.
I believe, in the whole code, 'Order = tlgrade' code part shouldn't appear for a linear graph case. How can 'Order = tlgrade' dissapear (for linear trendline case) or appear (for polynomial trendline case) in the code structure?
Here is my code:
Sub Macro1()
Dim tlgrade As Integer, tltype As String
tlgrade = Range("B10").Value
ActiveSheet.ChartObjects("Graph 1").Activate
ActiveChart.SeriesCollection(1).Trendlines(1).Select
If tlgrade = 1 Then tltype = xlLinear
If tlgrade > 1 Then tltype = xlPolynomial
With Selection
.Type = tltype
.Order = tlgrade 'I think this part conditionally should appear or dissapear as the case
.Forward = 0
.Backward = 0
.InterceptIsAuto = True
.DisplayEquation = True
.DisplayRSquared = True
.NameIsAuto = True
End With
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "B10" Then
Macro1
End If
End Sub
How can I solve it?
Thanks in advance. Best regards