Hi,
I am using the below piece of code to add a trendline to a graph. But it fails with runtime error 13 - type mismatch
Sub AddTrendline()
Dim GraphName As String
Dim TType As String
GraphName = Sheets("Control").Cells(11, 2).Value
TType = "xl" & Sheets("Control").Cells(9, 2).Value ' Tredline Type - Contains Linear
PO = Sheets("Control").Cells(10, 2).Value ' Trendline Parameter
Call UPS(Sheets("Control").Cells(11, 2).Value, "6785")
Sheets(GraphName).Select
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Trendlines.Add(Type:=TType).Select
Call PS(Sheets("Control").Cells(11, 2).Value, "6785")
End Sub
The varialble TType is instantiated correctly.
If I change the code to the below it works. I put the trendline type explicitly.
ActiveChart.SeriesCollection(1).Trendlines.Add(Type**:="xlLinear").**Select
Sub AddTrendline()
Dim GraphName As String
Dim TType As String
GraphName = Sheets("Control").Cells(11, 2).Value
TType = "xl" & Sheets("Control").Cells(9, 2).Value ' Tredline Type - Contains Linear
PO = Sheets("Control").Cells(10, 2).Value ' Trendline Parameter
Call UPS(Sheets("Control").Cells(11, 2).Value, "6785")
Sheets(GraphName).Select
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Trendlines.Add(Type:="xlLinear").Select
Call PS(Sheets("Control").Cells(11, 2).Value, "6785")
End Sub
How can I pass in a variable to set the trendline. The same would apply if I user Power or Polynomial types as there us a second parameter.
Reagrds
Tim