I have a spreadsheet in which I apply conditional formatting based on dates.
I have a named range called HOLIDAYS which I use to figure out the state of a given date (holiday, weekend …). The following formula is used to figure out if a day is a workday (1) or not (0). The date of the current row is stored in COLUMN()+2, just so this makes sense.
NETWORKDAYS.INTL(INDIRECT(ADDRESS(ROW();COLUMN()+2;1)); INDIRECT(ADDRESS(ROW();COLUMN()+2;1)); 1; HOLIDAYS)
I want to apply two formats that are in fact unrelated.
- One to set the background based on whether the week number is even or odd.
- The other to set the color and font style of the cells based on whether a day is a workday or not.
Therefore it would be great if I could have a condition that applies a style to the background and another that applies it to the font itself. I haven’t found such a way, therefore this question.
Currently instead I defined custom cell styles:
-
Workday in even week(font bold etc), based onWeek is even(see below) -
Workday in odd week(font bold etc), based onWeek is odd(see below) -
Week is even(background yellow) -
Week is odd(no background)
Then, using the following corresponding formula I check to apply the respective style (same order):
AND(IF(INDIRECT(ADDRESS(ROW(); 2; 1))=0);ISEVEN(INDIRECT(ADDRESS(ROW(); 1; 1))))AND(IF(INDIRECT(ADDRESS(ROW(); 2; 1))=0);ISODD(INDIRECT(ADDRESS(ROW(); 1; 1))))ISEVEN(INDIRECT(ADDRESS(ROW(); 1; 1)))ISODD(INDIRECT(ADDRESS(ROW(); 1; 1)))
Here the column 2 contains the result from the formula at the top, stating if a day is a workday (1) or not (0). Column 1 contains the week number, which governs the background style.
This works, but it seems cumbersome.
Is there a more succinct way to apply two styles - where the styles control unrelated aspects such as background vs. font style - using conditional formatting?
Thanks.
- I answered literally, while Vladyslav will provide a way to solve the task of formatting with simpler way (but that would not mean that two cell formats will be active at the same time, defining different subsets of the resulting cell formatting - unless it’s by inheritance) - after all, the Ask site is about helping users make their job done, in which Vladyslav is one of the best wizards here.
