0
votes

I am trying to set conditional formatting rules based on dates such that a date entered into one tab in the Google Sheets is compared with a date in another tab, which is in turn selected based on a value in another tab. The application here is to have dates turn red when they fall outside a date range that is chosen based on a cycle number. For example, if cycle 005 runs from 05/08/17 to 05/21/17 and the date entered in a range of cells (there is a "from" and "to" column) is 05/07/17 (before the earliest date in the cycle) or 05/20/18 (after the latest date in the cycle) then the cell will turn red.

I have one tab (called lookup_table) that has cycle numbers and their corresponding "from" and "to" dates, another tab (called review) where the cycle number for a given data set is entered (into cell B2), and a third data tab where "from" and "to" dates are entered. The formula needs to reference "from" and "to" dates in the lookup_table tab based on the cycle number in the review tab to conditionally format the dates entered into the data tab.

I have found some similar questions about conditional formatting but nothing involving putting together a "nested" function comparing dates after referencing them based on another value.

1

1 Answers

1
votes

Conditional formatting with a formula can use nested logic, because the formula can be nested, =if(...if(...vlookup(...))) and so on. When a reference to another sheet is made in a conditional formatting formula, it should be wrapped as indirect, i.e., review!B2 should be replaced by indirect("review!B2").

Step 1: get cycle number, review!B2

Step 2: Look up "from" date, =vlookup(review!B2, lookup_table!A:C, 2, False). The assumption here is that in the lookup table, cycle numbers are in column A and From dates are in column B. (2nd column of the range)

Step 3: Add conditional formatting rule, "Date is before"... "exact date" and enter the formula from step 2 in "exact date", wrapping cross-sheet references in `indirect as mentioned earlier.

=vlookup(indirect("review!B2"), indirect("lookup_table!A:C"), 2, False)`

Step 4: Look up "to" data, =vlookup(review!B2, lookup_table!A:C, 3, False). The assumption here is that in the lookup table, cycle numbers are in column A and From dates are in column C. (3rd column of the range)

Step 5: Add conditional formatting rule, "Date is after"... "exact date" and enter the formula from step 4 in "exact date", wrapping cross-sheet references in `indirect as mentioned earlier.

=vlookup(indirect("review!B2"), indirect("lookup_table!A:C"), 3, False)`