Stephen's example uses no VBA. It's a little obscure unless you have a lot
of experience with named ranges and the like. Perhaps I can give an easier
example. I'll stick with Stephen's data:
PLANT VOLUME CUM VOLUME COST
A 10 0 50
B 60 10 30
C 40 70 65
D 130 110 45
The total volume is 240, so the simplest thing to do is set up another range
in the worksheet, say columns L
. Keep L1 blank. In M1
1 put the labels A,
B, C and D. In L2:L241 put the numbers 1 to 240 (one row per unit of
volume). The range M2:M11 consists of 10 rows for the 10 units of A volume,
and they contain the value 50, A's cost. The range N12:N71 (60 rows)
contains the value 30. O72:O111 (40 rows) contains the value 65, and
P112
241 (110 rows) contains the value 45. In abbreviated form, the range
looks like this:
Col L Col M Col N Col O Col P
Row 1 A B C D
Row 2 1 50
Row 3 2 50
....
Row 10 9 50
Row 11 10 50
Row 12 11 30
Row 13 12 30
....
Row 70 69 30
Row 71 70 30
Row 72 71 65
Row 73 72 65
....
Row 110 109 65
Row 111 110 65
Row 112 111 45
Row 113 112 45
....
Row 240 239 45
Row 241 240 45
The range L1
241 is plotted in a stacked column chart in Stephen's example,
or in a stacked bar chart in yours. The columns/bars are formatted with a
fill color but no border.
To make the chart more dynamic, insert five rows above L1
1. Transpose
Stephen's data and put it into the inserted rows (L1
4):
Col L Col M Col N Col O Col P
Row 1 A B C D
Row 2 Volume 10 60 40 130
Row 3 Cum Vol 0 10 70 110
Row 4 Cost 50 30 65 45
Row 5
Row 6 A B C D
Row 7 1 50 0 0 0
Row 8 2 50 0 0 0
....
Row 15 9 50 0 0 0
Row 16 10 50 0 0 0
Row 17 11 0 30 0 0
Row 18 12 0 30 0 0
....
Row 75 69 0 30 0 0
Row 76 70 0 30 0 0
Row 77 71 0 0 65 0
Row 78 72 0 0 65 0
....
Row 115 109 0 0 65 0
Row 116 110 0 0 65 0
Row 117 111 0 0 0 45
Row 118 112 0 0 0 45
....
Row 245 239 0 0 0 45
Row 246 240 0 0 0 45
Cell M7 has this formula:
=IF(AND($L7>M$3,$L7<=M$2+M$3),M$4,0)
Copy cell M7, then select the entire range M7
246, and Paste. This puts the
formula into the entire range. The chart is now made from the range L6
246.
One more refinement will disconnect the length of the chart source data
range from the volume values. Suppose we decide 100 columns/bars in the
chart provides all the resolution we need. Put the numbers 1-100 into
L7:L106, and delete everything from L106
107 and below. Change the formula
in M7 to this:
=IF(AND($L7>100*M$3/SUM($M$2:$P$2),$L7<=100*(M$2+M$3)/SUM($M$2:$P$2)),M$4,0)
and fill M7
106 with this new formula. The resulting table is much smaller
but the chart is essentially the same:
Col L Col M Col N Col O Col P
Row 1 A B C D
Row 2 Volume 10 60 40 130
Row 3 Cum Vol 0 10 70 110
Row 4 Cost 50 30 65 45
Row 5
Row 6 A B C D
Row 7 1 50 0 0 0
Row 8 2 50 0 0 0
Row 9 3 50 0 0 0
Row 10 4 50 0 0 0
Row 11 5 0 30 0 0
Row 12 6 0 30 0 0
....
Row 34 28 0 30 0 0
Row 35 29 0 30 0 0
Row 36 30 0 0 65 0
Row 37 31 0 0 65 0
....
Row 50 44 0 0 65 0
Row 51 45 0 0 65 0
Row 52 46 0 0 0 45
Row 53 47 0 0 0 45
....
Row 105 99 0 0 0 45
Row 106 100 0 0 0 45
Stephen's technique merely defines some named formulas that represent the
data in the formulas without using a range as above to hold the data.
However, this makes it more difficult to examine and debug the data.
- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______