Microsoft Office Tutorials and References
In Depth Information
Try It
Try iT
In this lesson you create an embedded pie chart, position it near the source data, and give each
legend key a unique color. The pie will have four slices that will each be given a unique color, and will
each display their respective data labels.
lesson requirements
To get the sample database files you can download Lesson 14 from the book’s website at
www.wrox.com .
step-by-step
1.
Insert a new worksheet and construct the simple table
as shown in Figure 14-4.
2.
From your worksheet, press Alt+F11 to go to the
Visual Basic Editor.
3.
From the VBE menu, click Insert Module.
4.
In your new module, enter the name of this macro,
which I am calling TryItPieChart . Type Sub
TryItPieChart , press the Enter key, and VBA will
produce the following code:
Sub TryItPieChart()
figurE 14-4
End Sub
5.
Declare the ChartObject variable.
Dim chtQuarters As ChartObject
6.
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)
7.
Define the range for this pie chart:
chtQuarters.Chart.SetSourceData Source:=Range(“A3:B7”)
8.
Define the type of chart, which is a pie:
chtQuarters.Chart.ChartType = xlPie
9.
Activate the new chart to work with it:
ActiveSheet.ChartObjects(1).Activate
 
Search JabSto ::




Custom Search