Have you considered using a Pivot Table to do the heavy lifting?
Try this (using your sample file)
Add a heading to the Color column (C9: Color)
Then...from the Excel Main Menu
<data><pivot table>.....................Click [Next]
Set the data range ($A$9:$D$24).....Click [Next]
Click the [Layout] button
ROW: Drag the Code and ProductName fields here
(Double-click on each field and set Subtotals to None)
COLUMN: Drag the Color field here
(Double-click on the field and set Subtotals to None)
DATA: Drag the Amount field here
If it doesn't display as Sum of Amount...
Double-click on it and set the formula to SUM
Click [OK]
Select a destination cell to build the Pivot Table (eg Z15)
Click [Finish]
The finished Pivot Table will look like this:
Sum of Amount Color
Code ProductName black blue brown green orange purple red white yellow
000001 AB 30 40 20 70 15 20 10
000002 CD 100 500 30 70 1000
000003 EF 10 10 30
Note: I set the Grand Totals for the table to None
I also edited the last 000002 product name to "CD"
Is that something you can work with?
Bookmarks