title: Check if Trendline Exists in VBA
body: <p>I have a sheet with a chart in it. I need to insert a button to TOGGLE the Trendline On/Off. So first, I need to check whether a trendline exists or not. Sounds simple, but is driving me NUTS!!!</p>
  
  <p>Here is the code that I use to create the trednline and format it:</p>
  
  <pre><code>Sub Trending() 
  
  Sheets("Sheet1").ChartObjects(1).Activate
      ActiveChart.SeriesCollection(1).Trendlines.Add
      ActiveChart.SeriesCollection(1).Trendlines(1).Select
      With Selection
          .Type = xlPolynomial
          .Order = 3
          .Border.ColorIndex = 3
          .Border.Weight = xlMedium
  
      End With
  
  End Sub
  </code></pre>
  
  <p>To check for the existence of a trendline, I tried:</p>
  
  <pre><code>If Sheets("Sheet 1").ChartObjects(1).SeriesCollections(1).Trendlines(1).Count = 1 Then
      [Statement]
  End If
  </code></pre>
  
  <p>But the test fails. </p>
  
  <p>What am I doing wrong? What is a non-dirty way to do it?</p>
  
  <p>Thanks,
  Al</p>