title: Add Data Labels with VBA
body: <p>I have a <strong>Sub</strong> based off a <strong>checkbox</strong> that I want to essentially switch between showing data labels on a graph and hiding them. I recorded the macro and altered it to no longer say <strong>"Selection"</strong> or <strong>"ActiveChart"</strong> because I don't want to have the user select the chart. I think that's where my problem is because it does absolutely nothing.</p>
  
  <p>I can't seem to narrow down the issue since it's a rather long chunk. Any help would be appreciated!</p>
  
  <pre><code>Sub Checkbox()
  Dim Cht As ChartObject
  Set Cht = Sheet5.ChartObjects("Chart 12")
      If Sheet1.Range("W11") = "TRUE" Then
      Cht.Chart.SetElement (msoElementDataLabelTop)
      Cht.Chart.ApplyDataLabels
      Cht.Chart.FullSeriesCollection(1).DataLabels.Select
      Cht.ShowCategoryName = True
      Cht.Separator = "" &amp; Chr(13) &amp; ""
      With Cht.Format.Fill
          .Visible = msoTrue
          .ForeColor.RGB = RGB(127, 127, 127)
          .Solid
      End With
      With Cht.Format.Fill
          .Visible = msoTrue
          .ForeColor.ObjectThemeColor = msoThemeColorAccent1
          .ForeColor.TintAndShade = 0
          .ForeColor.Brightness = 0
          .Transparency = 0
          .Solid
      End With
      With Cht.Format.Fill
          .Visible = msoTrue
          .ForeColor.RGB = RGB(68, 114, 196)
          .Transparency = 0.75
          .Solid
      End With
      Application.CommandBars("Format Object").Visible = False
      Else: Cht.Chart.SetElement (msoElementDataLabelNone)
      End If
  End Sub
  </code></pre>
  
  <p>I was told a while ago it's better to reference a cell rather than a checkbox, hence the reason I have the code looking at W11 for "TRUE" or "FALSE". I would rather use the checkbox if it seems practical.</p>