Then we??™ll explore options to reuse the
code and automate the creation of pie charts for each product line.
1. Select the Sales By Category worksheet.
2. Create a new macro and name it MakePieChart.
3. Select the data range that contains the data for the Baked Goods & Mixes category
(A2:C5), as shown in Figure 5-18.
Figure 5-18. Selection for pie chart
CHAPTER 5 n CHARTING IN EXCEL 2007 206
4. On the Insert ribbon, select Pie from the Charts section, as shown in Figure 5-19.
Figure 5-19. Selecting a 2D pie chart from the ribbon
The pie chart is displayed, but as Figure 5-20 shows, it is not exactly what we might
have expected. Excel combined the first two columns of data and created the legend
from them. The data itself is fine. With a couple of quick adjustments, we will modify
the legend to show the month name only, and we??™ll add a title to the chart showing the
product category.
Figure 5-20. The new pie chart as created
CHAPTER 5 n CHARTING IN EXCEL 2007 207
5. With the Macro Recorder still running, select the pie chart if it??™s not already selected.
6. Go to Chart Tools ?¤ Design ribbon, and choose the Select Data command, as shown in
Figure 5-21.
Figure 5-21. The Select Data command
7. The Select Data Source dialog box will appear, as shown in Figure 5-22.
Figure 5-22. The Select Data Source dialog box
The Select Data Source dialog box contains functions to set the data range for the
chart, to switch row/column orientation, to assign a range that contains the data values
for the chart series, and to assign a range that contains the legend information.
Pages:
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206