The proper means in this arena should be Conditional Formatting. It has its disadvantages, though.
-
(Only felt so?) You can apply only named styles.
-
Well established usage requires an extra condition for everyone of the styles to be applied conditionally.
-
There are issues (“bugs”).
Another approach some would prefer and I woul discourage taking is programming.
There is an undocumented (?) method using CF I recently got aware of reading in another thread of one of the forums (I unfortunately cannot find at the moment): Use the style function inside an (the only then) CF condition in a way calculating conditions or choosing styles by other means. Evaluating it will apply the named style last touched in a calculation to the cell despite the overall condition (best) being never true. Though this is not in contradiction with the documented use of STYLE() I was surprised this worked.
Playing around with your example I couldn’t get it working under V4.3.3 but this may have been related to my user profile. Just having installed 4.3.4.1 the before created document is working well.
You will have to decide if you accept somewhat fragile constructs. See attached example!