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
Select a destination cell to build the Pivot Table (eg Z15)
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?