Whilst a macro could certainly be written to do this, there are 3 other
techniques, none of them needing VBA, which you ought to consider first,
particularly since these will do what the VBA you seek will not, which
is react to additional data input.
The first and potentially most flexible and quickest is to create a
pivot table and there are many web guides to doing this if you've never
done it.
The second and third are to use array formulae or D-functions; if you
have a lot of data I'd recommend the latter. I have articles on how to
use these here:
http://www.grbps.com/Excel5.pdf (array formulae)
http://www.grbps.com/Excel3.pdf (D-functions)