Microsoft Office Tutorials and References
In Depth Information
Try It
10.
Color the legend entries to identify each pie piece:
With ActiveChart.Legend
.LegendEntries(1).LegendKey.Interior.Color = vbYellow
.LegendEntries(2).LegendKey.Interior.Color = vbCyan
.LegendEntries(3).LegendKey.Interior.Color = vbRed
.LegendEntries(4).LegendKey.Interior.Color = vbGreen
End With
11.
Add data labels to see the numbers in the pie slices:
ActiveChart.SeriesCollection(1).ApplyDataLabels
12.
Edit the chart title’s text.
ActiveChart.ChartTitle.Text = “Quarterly Sales”
13.
Format the legend:
ActiveChart.Legend.Select
With Selection.Font
.Name = “Arial”
.FontStyle = “Bold”
.Size = 14
End With
14.
Deselect the chart by selecting a cell:
Range(“A1”).Select
15.
Press Alt+Q to return to the worksheet, and test your macro, which in its entirety will look as
follows. The result will look like Figure 14-5, with a pie chart settled near the source data.
Sub TryItPieChart()
‘Declare the ChartObject variable.
Dim chtQuarters As ChartObject
‘Set the variable to the chart being added.
‘Position the chart near the source data.
Set chtQuarters = _
ActiveSheet.ChartObjects.Add _
(Left:=240, Width:=340, Top:=5, Height:=240)
‘Define the range for this pie chart.
chtQuarters.Chart.SetSourceData Source:=Range(“A3:B7”)
‘Define the type of chart, which is a pie.
chtQuarters.Chart.ChartType = xlPie
‘Activate the new chart to work with it.
ActiveSheet.ChartObjects(1).Activate
Search JabSto ::




Custom Search