Conditional formatting based on adjacent cell value even when the first adjacent cell in row is blank - google-sheets

I would like to colour cell C3 red, as the value is less than the next filled cell on row 3 (E3).

You need custom formula in the formatting rules for range C2:W.
And you can use the formula below for green:
=and(not(isblank(C2)),C2>index(filter(D2:$W2,arrayformula(not(isblank(D2:$W2))))),1,1)
And make another conditional formatting rule with the same range and change > accordingly for red.
Note that the equal case does not have formatting in your example.
To understand why, there are a few components at work. I'll give an outline in case OP or any passer-by wants one.
First is how conditional formatting in Google Sheet works. I will be brief here. The range we put in the rule is C2:W. Google Sheet will use the beginning cell in that range as a reference. For C2:W, the 1st cell is C2. In the formula, the cells are read in terms of relative position to that reference cell. So when evaluating formatting for cell C2, it treats the formula as is. But, for example, when evaluating formatting for cell C3, Google Sheet iterates all non-fixed ranges by 1 row. Another example: for D3, all non-fixed ranges are iterated by 1 row and 1 column.
Whenever the formula evaluates to true, the format will be applied -- although that is subject to further formatting if you have subsequent formatting rules which apply to the given cell.
Next are the components of the conditional formula.
not(isblank(C2)) checks for blank cells and makes the whole formula only true when the cell is non-blank.
For filter() usage, please consult official documentation. I will explain how filter() is applied to your example.
In our use, we are trying to rid of empty cells in the range that is on the same row as the cell in question and goes from the next column to column W. (I am using column W because there is no known end column in your image. Please adjust to your application accordingly.) Same row as C2 means row 2. Hence the digit 2 in D2:$W2. No $ sign for row because row index is meant to iterate through our range C2:W in the formatting rule. No $ sign for D because we mean 1 column next to the cell in question and the exact column index should iterate. We fix column W because the end column does not evolve and is thus not meant to iterate. Neglecting this will not particularly change the result in your example. However, it is good to be clear with the meanings.
arrayformula(not(isblank(D2:$W2))) produces a local row array whose cells are true/false that each represents whether the corresponding cell is non-blank. filter() in turn only keeps cells from D2:$W2 for cells in arrayformula(not(isblank(D2:$W2))) that are true.
We only care about the 1st non-blank cell. To retrieve the 1st cell from a (local) array, we use index(...,1,1). (That said, omitting index() also happens to work for the 1st cell in particular because when comparing a single cell with > or < to an array range, only the 1st cell of the array is used.)

Apply a conditional formatting to the range desired (starting from cell C2) using this formula:
=IF(C2="",FALSE,OFFSET(C2,0,AGGREGATE(15,6,(COLUMN(D2:W2)-COLUMN(D2)+1)/(D2:W2<>""),1))>C2)

Related

How to conditional format each row of a column based on corresponding value in another column

Please refer the image
I want the cell to be highlighted based on the value is less than or greater than the value in the benchmark column. I am not able to do that using conditional formatting custom formula. I have manually applied formatting for 02/01/2023 . I want the formatting to apply to the column with date = today() only.
Thanks :)
I can write a custom formula for each row of each date column. But is there any way a single custom formula that could format across rows and columns?
I'm guessing your fist value of 02/01/2023 and Activity1 is C2. Then for the whole range C2:Z (or whichever you have):
=C2>=$B2
Do this for one color for the whole range and it will drag automatically, you don't need to write it as an arrayformula. The "$" will always refer to the value in column B from the row it's positioned
if you are selecting whole range (C2:Z), try this for green and red respectively:
=(C2>=$B2)*(C2<>"")
=(C2<$B2)*(C2<>"")

Making a formula that checks for a sheet with the same name as the cell next to it

I have this formula which sums up several columns in another sheet. The sheet that the formula is referencing to always has the same name as the cell next to it.
Instead of having to rewrite the formula for every cell in the column, is there a way I can just simply check for a sheet with the same name as the cell next to it? The cell ranges will always be the same.
You should use INDIRECT formula. This allows you to write references as strings.
Instead of 'Round 3'!C5:C you can write: INDIRECT("'"&C2&"'!C5:C") (assuming that word Round 3 is in C3).
Whole function looks like this (assuming that active cell is D2)
=SUM(INDIRECT("'"&C2&"'!C5:C"),INDIRECT("'"&C2&"'!G5:G"),INDIRECT("'"&C2&"'!K5:K"),INDIRECT("'"&C2&"'!O5:O"),INDIRECT("'"&C2&"'!S5:S"))

How to use ARRAYFORMULA with OFFSET to previous row without getting circular reference error

Example sheet: https://docs.google.com/spreadsheets/d/14ma-y3esh1S_EkzHpFBvLb0GzDZZiDsSVXFktH3Rr_E/edit?usp=sharing
In column B of ItemData sheet, I have achieved the result I want by copying the formula into every cell in the column, but I want to solve this using ArrayFormula instead.
In column C I have achieved the same result using ArrayFormula. However, for addition, column C is referring to cells in column B, while column B is referring to cells in column B. I.e. every cell in column B is adding 1 to the cell on the row above.
If I select the C3 formula text and paste it into the cell edit field for cell B3 (to not screw up cell references during copy - I know I could make them static references, but this is not my problem), the cell gets an error value of
#REF!
Error
Circular dependency detected. To resolve with iterative calculation, see File > Spreadsheet Settings.
Do note that the additions that need to be done are the same in both cases: Add 1 to the value of the cell on the previous row, so there is no circular reference involved. There is a starting value provided in B2, and cells in B3 and downwards should use the data from the B cell in the previous row.
Also, note that I did try File->Spreadsheet settings and enabling circular reference computation with max 25 items, but this only fills in the first two cells (B3 and B4).
How can I solve this problem? I would prefer having something like ArrayFormula, where the formula only exists in a single cell. But copy-pasting would be acceptable as long as any new rows, inserted in between or added at the bottom, would get the same formula added in column B.
Will matching items always be consecutive? It seems that way since you're comparing each Item cell to the cell above it right in your formula logic. That breaks an [unwritten?] rule of spreadsheet normalization; values' addresses themselves generally should not be treated as data.
IF you're committed to it though, have you considered explicitly using location as a data source? Example:
=ARRAYFORMULA(IFS(
NOT(LEN(A3:A40)),,
ROW(A3:A40)-3-MATCH(A3:A40,A$3:A$40,0)<=VLOOKUP(VLOOKUP(A3:A40,Items!$A$2:$D,2,false),DataPerColor!$A$2:$B,2,false),ROW(A3:A40)-3-MATCH(A3:A40,A$3:A$40,0),
true,
))
Just like your formulas, all that does in English is:
for each row,
if there's no Item, don't output any ItemData,
if the number that belongs in this cell¹ is less than or equal to the lookup, print it,
otherwise, don't output any ItemData
But then what is ¹ "the number that belongs in this cell" and how can we calculate it without using column B? I abuse locations of things to get it. Looking down your row B, each number that appears is just:
this row's number,  minus  
the row where items start [always 3],  minus  
the row number [in just the Item rows] of the first row containing this row's Item
Using the second-to-last ItemC as an example: the first ItemC is the 16th item listing, and the one we're looking up… the "second-to-last ItemC" is in row 21 of the sheet. 21-3-16 = 2 …the number you wanted.
If you can stomach that, it's a single formula and does work according to your specifications.

Google Sheets - How to highlight cells in a row that match values from other cells?

I have a row of values (say 1-10)
At the beginning of the rows I have 2 numbers generated from dates from other cells that represent week numbers. (eg, 3 and 9)
I want my row to highlight all the numbers from 1-10 that are between the values from the week number cells. (eg the cells with numbers 3,4,5,6,7,8 and 9 will automatically turn a colour (say green))
I've tried the conditional format, using the "between" values.
It doesn't work.
If I just type the numbers into the format box, it will work, but the problem is I need it to refer to the value in the cell NOT a number I type in, because there is a likelihood that the dates could change, which will affect the value shown in week number cell, so I need it to work automatically and not require me to go through every single row changing values for the formatting.
Is this even possible on sheets?
Thanks in advance, I am hoping I've just overlooked something simple.
Use a custom function for conditional formatting. For instance, if the columns you describe are in Row 2, this function will evaluate "TRUE" for numbers that are >= A2 and <= B2:
=AND(C2>=$A2,C2<=$B2)
Select the range of cells you wish to create a conditional format for; C2..L2, say. Open the conditional formatting dialog, and choose "Custom formula". Enter the formula above; note that itr refers to the top-left corner of the range you wish to apply the formula to - Sheets will automatically adjust it for the rest of the range, which is why it's important to use absolute references for the first two columns.

Conditionally color Google Spreadsheet cell if value matches different column in same row

I have a Google Spreadsheet with data values in the first 10 columns (A through J) and the 11th column (K) has a reference value. This pattern repeats for 150 rows
So, for the first row, A1 through J1 are the data values and K1 is the reference value.
And for the 25th row, A25 through J25 are the data values and K25 is the reference value.
Now, for any data cell (cells within the first ten columns), where the value in the cell matches the value in the corresponding reference cell (at column K in the same row as the data cell), I want to change the background color of the data cell.
So, for data cell A1: if value in A1 == value in K1, change background color of A1
And, for data cell C23: if value in C23 == value in K23, change background color of C23
I assume that conditional formatting should be able to do this, but I could not figure out how. I know how to do conditional formatting for a single cell, but I can't figure out how to apply conditional formatting to the entire table (cells A1 through J150) at once.
Use the following custom formula in conditional formatting:
=A1=$K1
and apply to range A:J.
To exclude blank cells (and cells with zero-length text strings), try:
=AND(LEN(A1),A1=$K1)

Resources