Generalised conditional formatting function