Condition Formatting not Working in Google Spreadsheet - excel

I have written a formula:
=IF(len(d2)>0,IF(d2=0,true,false),IF(len(e2)>0,IF(e2=0,true,false),false))
I want to strike through entire row if the formula returns true. But it is not working. Annoying facts are:
If I place this formula into a cell, it shows correct true or false value.
If I apply this formula on entire row, only A2 and B2 cells are formatted.
To test whether there is come conflict with other formatting rules, I just removed the formula, and just wrote "true" in the custom formula column. And the entire row was formatted. I pasted formula into a cell and it was also returning true. How does the fomula which is returning true in the cell is returning false in conditional formatting?
I applied the formula to cells which have no other conditional formatting rules. The formula didn't work. So how the formula was working for A2 and B2 cells?
I tried using values other than true/false. As usually, it worked perfectly in cell, but not in conditional formatting.
It is not working even on fresh spreadsheet.
Please check it yourself. To get "True" value from the formula, enter 0 in d2 and e2 and see yourself that conditional formatting is not respecting it.
Thanks in advance for giving time to read the question.

The reason that the formula is only working for cells A2 and B2 is because D2 and E2 in the formula are relative references, which means that these cells in the formula shift as the cell which is applying the conditional formatting also shifts.
In other words, cell A2 considers this as the formula:
=IF(LEN(D2)>0,IF(D2=0,TRUE,FALSE),IF(LEN(E2)>0,IF(E2=0,TRUE,FALSE),FALSE))
And cell B2 considers this as the formula:
=IF(LEN(E2)>0,IF(E2=0,TRUE,FALSE),IF(LEN(F2)>0,IF(F2=0,TRUE,FALSE),FALSE))
Notice how the formula had the cells shift over.
The problem occurs when it gets to cell C2, which considers the formula as this:
=IF(LEN(F2)>0,IF(F2=0,TRUE,FALSE),IF(LEN(G2)>0,IF(G2=0,TRUE,FALSE),FALSE))
Presumably neither F2 nor G2 contains the data you're looking for, which is why the conditional formatting rule is not applied.
To fix this, you can change the formula to an absolute reference so that it always refers to the D and E columns, like so:
=IF(LEN($D2)>0,IF($D2=0,TRUE,FALSE),IF(LEN($E2)>0,IF($E2=0,TRUE,FALSE),FALSE))
This way, all cells in the 2nd row will consider precisely the above formula when checking the formatting (i.e. the cells will not shift).
On a side note, parts of your formula are redundant.
= IF(<condition>,TRUE,FALSE)
is equivalent to just
= <condition>
And additionally, if a third argument in an IF statement is not specified, FALSE is the default.
That being said, this formula can be simplified to:
=IF(LEN($D2)>0,$D2=0,IF(LEN($E2)>0,$E2=0))

Related

Is there a way to get the ISTEXT formula to ignore if there is a formula is the reference cell?

I have a simple formula:
=IF(ISTEXT(A3),"EA"," ")
I just need the cell with this formula to return EA is there is text in A3. The problem is the column A is feeding off of another sheet so each cell has a formula in it. My ISTEXT formula keeps returning EA even though the cell itself is blank. I'm guessing this is due to the cell having a formula in it. Any ideas how to make the ISTEXT ignore formulas?
I'd just check the length of the cell:
=IF(LEN(A3)>0,"EA","")

how to write an if statement code to compare two cell's value in one sheet to another cell in another sheet

i have two columns (Start Date, End Date) and i want a code that changes the color of both their cells to red if the start date and end date contained any date located in another sheet
I tried using conditional formatting using this rule: =AND(C2<=Holidays!$A$2:$A$15,D2>=Holidays!$A$2:$A$15)
Tested out the below formula for myself and think it should work! Effectively rather than a simple AND statement, since we're comparing against an array of values rather than single cells, we need to use some handy array formulas. This post gives a good breakdown of what's going on under the hood: https://exceljet.net/formula/index-and-match-with-multiple-criteria
Apply this formula in conditional formatting, assuming the range you're formatting starts at C2.
=SUM((Holidays!$A$2:$A$15>$C2)*(Holidays!$A$2:$A$15<$D2)) > 0
Also, wanted to call out the absolute references specified for columns. I've specified **$**C2 and **$**D2 in my formula, which means that no matter which cell in your conditional formatted range it'll evaluate off the values in column C and D. In your current formula, cell C2, would evaluate on C2 and D2, but cell D2 would then evaluate off D2 and E2. This'd be why when you tried the manual formatting only the start date cells (column C) were formatting correctly.
Hope this helps!
Update::
If you had a table format like in the attached screenshot, you would apply the conditional formatting formula:
=SUM((Holidays!$A$2:$A$15>$C2)*(Holidays!$A$2:$A$15< $D2)) > 0
To cell range $C$2 : $D$3
If you're changing the cell range (say you wanted to apply to $C$10 : $D$14), you'd just change the $C2 and $D2 in the formula --> $C10 and $D10.

How to calculate conditional cell formula, with adjacent cell formula dependent on 1st cell's calculated, not printed value?

I am trying to figure an Excel formula and Google is not helping.
I almost have what I am trying to do, but need a 'dummy' column where I do the math in the column cells.
What this means:
1) What I have working:
Cell A1, with math formula (I wish to delete this 'dummy' cell and incorporate this into the formula in Cell B1, see further explanation below)
=SUM((6.75*1)+(5.73*2)+3)
Cell B1, with value from Cell A1 but limited to an integer less than or equal to 80
=IF(SUM(A1)>80, 80, SUM(A1))
Cell C1, with a value looking at Cell B1 and entering in this cell either 0 or any integer greater than 80
=IF(SUM(A1)>80,SUM(A1)-80,"0")
Note: This works perfectly, I change any values in the Cell A1 formula and it correctly reflects in Cells B1 & C1.
2) The missing piece:
I would like to combine the two formulas above in cells A1 & B1 into one cell, and still have the same results described above for each of the cells.
To articulate this another way is:
have a cell with a math formula,
calculate the results of that formula, and then,
enter back in the same cell that formulas results,
with the condition of 'less than or equal to 80'
while a formula in an adjacent cell is dependent on the calculated, but un-printed, value of the first cell.
As an example:
Using only Cells A1 and B1 in a spreadsheet, and combining the above working formulas (which do not work for me in Excel), it would look like this:
Cell A1:
=IF(SUM((6.75*10)+(5.73*7)+8.5)>80, 80, SUM(B21))
Note: Cell A1 formula from above, =SUM((6.75*1)+(5.73*2)+3), combined with Cell B1 formula from above, =IF(SUM(A1)>80, 80, SUM(A1)) (with the Cell A1 formula replacing both 'A1' values in the Cell B1 formula).
Cell B1:
=IF(SUM(A1)>80,SUM(A1)-80,"0")
Note: Identical to the Cell C1 formula above.
Is it possible to do this, calculate the results of a cell's formula, while a formula in an adjacent cell is dependent on the calculated, but un-printed, value of that first cell?
I realize writing this out, it's more complicated than I originally anticipated, which explains why Google wasn't getting me anywhere.
Thanks for any hints.
Phil
Strictly speaking, this is not possible. A cell has only 1 value and that is the result of all calculations. The IF statement is not hiding the value of the cell. It is changing the value.
A formula to another cell can only use the final value of the cell. It can't extract part of the formula in the other cell. There's no way for Excel to know which part to extract, even if there's only a single calculation in an IF statement.
That said, there is a different workaround possible in your case... and that is to change how your value is displayed through custom formatting. Formulas change the value of cells, whereas formatting changes how those values are displayed.
Place your formula in cell A1: =6.75*10+5.73*7+3
Right click on cell A1 and select Format Cells...
Make sure you're on the Number Tab
In the Category column, select Custom
Enter this formula in the Type box: [>80]"80";[<=80]General
Enter this formula in B1:=IF(A1>80,A1-80,0)
Check that the number format of B1 is still "General" or "Number"
The result is A1 has calculated and stored the actual value, but displays the text string "80" if it's value is above 80. You can then use the actual value from A1 in other formulas.
NOTE: This type of custom formatting is extremely poor practice as it can become very confusing and very error prone. The value of the cell is different to what it is showing and if other users are unaware, creating new formulas referring to the affected cell can unwittingly produce incorrect and/or unexpected results.
In particular, Excel tries to be helpful and can automatically copy the formatting from one cell to another if it is next to the original cell or if it refers to only the original cell in a basic formula. Copying and pasting also copies the formatting by default. Unintentionally copying the formatting to other cells will also alter how they appear.
Also note that you don't need to put SUM() around a formula that already had the addition operators included; and Excel uses order of operations so you don't need the brackets to do multiplication before addition.
Lastly, you could also just use =MAX(A1-80,0) in B1.

date formula to return blank if cell is empty

I have the following formula in cell R3. =If(Isblank(E3),"",(E3)+365. This formula gives me the date I am looking for if I have a date entered in cell E3. However cell E3 does not always have a date in it. When there is no date in cell E3 I get #Value in cell R3. Is there a way to leave R3 blank if no date entered in E3.
How about:
=IF(E3="","",E3+365)
Alternately you could wrap your entire formula within an IFERROR() function:
=IFERROR(IF(ISBLANK(E3), "", E3+365), "")
The advantage of this (or disadvantage depending on which way you look at it) is that it will also mitigate any other errors you might encounter from incorrect data types being placed into cell E3, such as #DIV/0, etc.

Conditional Formatting (If cell above and below is number, format only cell below)

I'am trying to create a conditional formatting which formats only cell below, but only if cell above and cell below both has number in them (negative or positive).
Now i got this:
=ISNUMBER(OFFSET(INDIRECT(ADDRESS(ROW(); COLUMN()));-1;0))
This formats the cell below if the cell above has a anything. It does not respect the condition where the cell below also must have a number.
Could somebody help me out here? I am realy stuck :)
EDIT:
So now i tried this:
=AND(ISNUMBER(INDIRECT(ADDRESS(ROW();COLUMN()))); ISNUMBER(OFFSET(INDIRECT(ADDRESS(ROW();COLUMN()));-1;0)))
But no luck whith this one either.
Just to clarify. This formula should run on $A$3:$BB$100
So for example if:
A5 = 10 (or any positive or negative number)
A6 = 10 (or any positive or negative number)
A6 should be formatet.
But if:
A5 = 10 (or any positive or negative number)
A6 = EMPTY
No formating should happen.
Hope this clarify what i'am trying to do :)
=AND(ISNUMBER(A5),ISNUMBER(A6)) This formula will also bypass formatting for A6 as well if both cells are empty. I assume that's what you want, as there's no value within either to format.
I see why we are getting different results with the formula. Conditional formatting is applied relative to the active cell when applied. Start with cell A2 as the first cell highlighted, (A2:A100),and then use this formula =AND(ISNUMBER(A2),ISNUMBER(A1)).Cell A2 should be the first active cell within the range of applied formatted cells.

Resources