SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 197 | Next

Jim DeMarco

"Pro Excel 2007 VBA"

The
index represents the order in which the series was added to the chart. In the case of our pie
chart, there is only one series. Here we are setting the name to the first value in the Category
column of our data range.
The last line of code changes the legend to simply show the month value without appending
the category to each legend item.
ActiveChart.SeriesCollection(1).XValues = "='Sales By Category'!$B$2:$B$5"
More Pie for Everyone
So we??™ve created a pie chart and modified some of its properties to make the data displayed
more meaningful. We??™ve got quite a few categories on our Sales By Category worksheet. Can
we use what we??™ve learned and the code we??™ve created to generate charts for the remaining
categories? Of course!
Excel does not always place charts in the most appropriate place on a worksheet, so
before we begin, let??™s be sure to move the Baked Goods & Mixes chart to the right of the
data range on the Sales By Category worksheet by dragging and dropping it, as shown in
Figure 5-28.
CHAPTER 5 n CHARTING IN EXCEL 2007 211
Figure 5-28. Chart moved next to data range
Next we??™d like to chart the Beverages product category in a manner similar to the Baked
Goods & Mixes pie chart. The simplest way to start is to copy the code from the MakePieChart
macro we just recorded and modify it to use the data range A6:C9, which contains the Beverage
category sales information.
1. If it??™s not already open, open the VBE by going to the Developer ribbon and selecting
Code ?¤Visual Basic, or by pressing Alt+F11.


Pages:
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209