1
votes

I'm making a spreadsheet journal with :
- a main entry on sheet1
- a static list of names and data on sheet2

In sheet1 I input values through Data Validation based on names in sheet2. Later on I add a value in sheet1. This value needs to be compared to a minimum and maximum value, that is listed in sheet2, and then color coded through conditional formatting based on a % deviation from the values in sheet2. For instance:

In sheet1 I have the data:

     A                          B
1    value                      OG 
2    British Brown Ale          1.045 

value British Brown Ale is input through the dropdown populated from the Data Validation list. In B2 I have a value for "OG" being 1.045.

In sheet2 the data looks like:

     A                          B          C
1    value                      min OG     max OG 
2    British Brown Ale          1.040      1.052 

In the row with "British Brown Ale":

  • in column 2 ("Min OG") I have a value of 1.040
  • in column 3 ("Max OG") I have a value of 1.052

Desired Result

I need to make:

  1. the range from 1.040 to 1.052 100% within the range and color code that green,
  2. If the value in sheet1!B2 was for instance up to 10% outside of this range it would be color coded yellow,
  3. and over 10% would be color coded red.

How do I use conditional formatting that can compare values like above?

Will I need scripts to achieve this?

1

1 Answers

1
votes

It's possible doing with only formulas. The best way is to use only ArrayFormula in order to make all formulas espand automatically.

Sheet2

Add two columns: "min - 10%" and "max + 10%"

in cell D2:

=ArrayFormula(OFFSET(B2,,,COUNTA(A2:A))/1.1)

in cell E2:

=ArrayFormula(OFFSET(C2,,,COUNTA(A2:A))*1.1)

The result:

enter image description here

Sheet1

4 formulas to get "min", "max", "min-10%", "max+10%"

in cell C2:

=ArrayFormula(VLOOKUP(OFFSET(A2,,,COUNTA(A2:A)),sheet1!A:E,2,0))

in cell D2:

=ArrayFormula(VLOOKUP(OFFSET(A2,,,COUNTA(A2:A)),sheet1!A:E,3,0))

in cell E2:

=ArrayFormula(VLOOKUP(OFFSET(A2,,,COUNTA(A2:A)),sheet1!A:E,4,0))

in cell F2:

=ArrayFormula(VLOOKUP(OFFSET(A2,,,COUNTA(A2:A)),sheet1!A:E,5,0))

And one formula to have color:

=ArrayFormula(if(--(OFFSET(B2,,,COUNTA(A2:A))<OFFSET(E2,,,COUNTA(A2:A)))+B2>F2,"red",if((OFFSET(B2,,,COUNTA(A2:A))>=OFFSET(C2,,,COUNTA(A2:A)))*(+OFFSET(B2,,,COUNTA(A2:A))<=OFFSET(D2,,,COUNTA(A2:A))),"green","yellow")))

The result:

enter image description here

Conditional Formatting rules for Sheet1

Select column B, add 3 new conditional formatting (CF) rules, custom formula:

first, paint green:

=$G1="green"

next, paint yellow:

=$G1="yellow"

next, paint red:

=$G1="red"

Then wou may hide extra columns.

The result:

enter image description here


I think, that's all is possible to do with only 3 huge arrayformulas inside CF, without doing extra columns, but it's hard to build one.