title: Set Legend Text Pie Chart
body: <p>I have been trying to set my two legends using a VBA Macro.</p>
  
  <p>I want to change my two legends from 1 and 2 to Male and Female on my Pie Chart.</p>
  
  <p>I can change it manually by setting it in the "Select Data Source" dialog by setting "Category (X) axis labels" to "=Sheet1!$B$6:$C$6" (which is Male and Female)</p>
  
  <p>How do I do this with VBA, though?</p>
  
  <p>Here is my code...</p>
  
  <pre><code>Sub Pie()
  
      For X = 7 To 13
          Charts.Add
          ActiveChart.ChartType = xlPie
          ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("b" &amp; X &amp; ":c" &amp; X)
          ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
          ActiveChart.HasTitle = True
          CellVal = Worksheets("Sheet1").Range("A" &amp; X).Value
  
          ActiveChart.ChartTitle.Text = "History statistics of " &amp; CellVal
  
      Next X
  
  End Sub
  </code></pre>