Google Sheets Conditional formatting based on another sheet - google-sheets

I built a Google Spreadsheets tracking the price of certain items in each month. The different items are displayed in row 3:30. Different retailers are displays in Column C:M. Each month is displayed in a different sheet. I want to match (for example) Cell C3 to Cell C3 in the month before and color Red if the price has increased, Green if the price has decreased and remain white if the price is the same. I want to do so for each of the cells C3:M30.
I have managed to find a formula to match cell C3 to C3 then cell C4 to C4 etc. untill cell C30. This is the formula I used:
=C3>INDIRECT("OKTOBER 2020!C"&ROW())
This works fine for Column C, but I can't find a way to incorporate Columns D:M in this formula. Is there a way to incorporate the conditional formatting rule for Columns D:M in the same formula? Or should I just add this formula to each row with the corresponding row Letter?

Answer:
You can do this with an ARRAYFORMULA.
Formula:
=ARRAYFORMULA(C3:M30>INDIRECT("OKTOBER 2020!"&SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","")&ROW()))
Rundown of this formula:
Creates an ADDRESS of a cell which has a row of 1, the current column index, using a relative reference.
Substitute the hard-coded row number 1 to extract out the column letter
Construct an indirect reference to the current cell using the extracted column letter, the current ROW(), and appending it to the string OKTOBER 2020!
Check if this cell is greater than the current cell
Run this whole formula on the range C3:M30. This can be expanded to cover additional cells, if necessary.
This formula checks if the price has gone up, for which the conditional formatting should reflect as such. You can also do this for when the price has decreased or stayed the same by changing the initial comparison operator:
Price decrease:
=ARRAYFORMULA(C3:M30<INDIRECT("OKTOBER 2020!"&SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","")&ROW()))
No price change:
=ARRAYFORMULA(C3:M30=INDIRECT("OKTOBER 2020!"&SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","")&ROW()))
References:
ARRAYFORMULA - Docs Editors Help
INDIRECT - Docs Editors Help
SUBSTITUTE - Docs Editors Help
ADDRESS - Docs Editors Help
COLUMN - Docs Editors Help
ROW - Docs Editors Help

Related

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

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)

Conditional Formatting Row based on

I like to use Google Sheets to keep my list of stories that I'm working on organized
like in this photo here:
Each row is highlighted a certain color depending on the value of the cell in "B" Column. "Published" is green, "WIP" is orange, where for range A2:B2, =B2="Published"
But at the moment I have to create the conditional formatting formula (CF) for each row one by one. I have to make the CF for Row 2, then copy the CF to Row 3 and edit the formula to replace every B2 with a B3 so it works independently on the next row.
This seems far too tedious to do practically so I was wondering if there was a formula that would allow each row to be formatted individually with one formula? Something where the formula knows to look at B2 in Row 2 to apply the formatting, B3 in Row 3, and so on.
The current formula I'm using is [=B3="Published"] to change the formatting style to a green highlight. But if I do this on all of my cells, it will change all of rows based on the value of B2. Even though in B3 it might be "WIP" instead, which defeats the purpose of highlight. I was hoping it would function like [if: =BX="Published"/ then: apply conditional formatting to Row X]
I'm really sorry about the poor phrasing of this question, I have basically zero knowledge on Google Sheets and don't know how to phrase the question for Google or any other search engine
set your range to A2:F and use this set of formulae:
orange
=$B2="WIP"
blue
=$B2="Outline"
green
=$B2="Published"

Google Sheets: how to sum a dynamic range across columns using a variable to determine range length

I'm trying to write a formula in Google Sheets that will enable me to sum a range of values across columns, where I can manipulate the number of cells to be summed across the column with a variable. For example:
if my variable is 5, then I want to sum(D3:H3);
and if my variable is 9, then I want to sum(D3:L3)
Furthermore, I want a formula that I can drag across columns so that the range it's summing moves relative to the cell the formula is in. In the example above with the variable=5:
the formula in cell A3 would be sum(D3:H3);
and the formula in cell B3 would be sum(E3:I3)
etc.
I created a sample spreadsheet here for more context.
Thanks for reading!
I've added a sheet ("Erik Help"). See formula in B5:P5.
Here is the B5 formula (which was then dragged across to P5):
=ArrayFormula(SUM(FILTER($B$1:$1,COLUMN($B$1:$1)>(COLUMN()-$B$4),COLUMN($B$1:$1)<=COLUMN())))
There may be an array approach. But since you have such limited data, this is just as effective with less time investment required to develop the solution.
In plain English, the formula reads "Sum the numbers from B1:1 where the column is greater than X rows back and no greater than the current column" (where X is the value set in B4).
paste in column B and drag to the right:
=IF(COLUMN()-1<$B1, "-", SUM(INDIRECT(
ADDRESS(3, COLUMN()-($B1-1))&":"&
ADDRESS(3, COLUMN()))))

Limit Number of Cells with the Same Value in Google Sheets

I'm looking to limit the number of cells that can have the same value in a column.
More precisely, I'm keeping track of people signed up for meeting dates and once four other people are assigned that date, it not to be an option anymore or highlight the cell in red? Something to alert that the meeting is already full.
Thanks in advance for any help or advice.
If highlighting the cell in red would be enough, then you can use this custom formula in your Conditional Format Rules.
Apply to range = A1:A
Custom Formula:
=countif(A:A,A1)>=4
What it does?
Increment a counter if duplicates are found in the given range using COUNTIF()
If the number of duplicates are >= 4 then set the background color of the cell to red
Sample:
Another variation if you have a different list of available dates to highlight and a list of booked dates
Apply to range = A1:A
Conditional Formatting Custom Formula:
=countif(C:C,A1)>=4
Highlighting of cells will only be applicable in Column A. It will check how many duplicates data in Column A exist in Column C using COUNTIF()

Conditional formatting based on cells matching a column of another sheet

I've got a spreadsheet made on Google Sheets that contains 11 sheets, and each sheet is a set of things that I'm considering buying.
Some sets contain the same individual pieces as something else.
For example item A might be on sheet A and sheet D.
I'd like to make some kind of formula to highlight all duplicates, so that when I was looking through the sheet I could see whether buying item A will help me complete more than just the set that I'm looking at. So I can look at a set and if it's mostly green I know there's more value in buying it as almost all of the contents will also go towards another set.
I know how to do it so that they glow if they match on the same sheet.
$A2=$B2
However I'm not sure how to do it across sheets, or how I'd include if statements. As the colour would have to change if it matches any cells in column A on any sheet. They're also not in the same order on different sheets so while item A might be in A3 on sheet A, it might be in A17 on sheet D.
I'm not sure how possible something like this is, but I'd appreciate any help.
Google Sheets does not allow direct references to cells in other sheets in conditional formatting formulas. But this can be circumvented with indirect:
= A2 = indirect("Sheet2!A2")
formats the current cell (A2) if it's the same as the contend of A2 on Sheet2.
But you want to check whether the content is duplicated anywhere in column A of another sheet. This can be done with match: select the column A2:A of the present sheet, and add conditional formatting with custom formula
=match(A2, indirect("Sheet2!A2:A"), 0) > 0
Here match returns either the position of found element (a positive number) or #N/A, and the formula evaluates to True in the former case only.
Although the formula says "A2", it can be applied at once to any range that has A2 as its upper left corner.

Resources