I don't know what "normal" coding relates to.

To reiterate, if the colour is being determined by logic [still unknown] then you should simply be looking to ape that same logic via a standard formula to conduct the count.

If you're formatting manually/arbitrarily then you have a few issues ...

1. Formatting a cell is not volatile action per se.
As a result of the above: assuming you can identify the colour (read on) you still can not be 100% sure that your calculations will be accurate all of the time
Using a Volatile construct will reduce the risk of error but will not remove it

2. If your version is XL2008 then obviously you have no VBA support so the more traditional routes (UDF) are not open to you.

3. If you can use older XLM calls then you might consider using those via Defined Names to retrieve the colour of a given cell (GET.CELL information 63).
However, you would I think (realistically) need to store the results per cell and calculate off those stored values.

The alternative would be to investigate creating full blown XLM scripts and/or use of AppleScript - neither of which I can help you with personally I am afraid.

If you are not using XL2008 - please state which version(s) you are using.