I can think of 2 possible solutions:

1. (easier solution) use '=SUMIF()' and '=COUNTIF()'; or
2. (better solution) use ADO and SQL.