I have a very unexpected outcome of OR used in conditional formatting formula.
Take a simple sheet:
Now add conditional formatting with formula:
=B4:G7=$A$1
It works as expected, with true value for cells containing "A"
Now try another formula:
=OR(B4:G7=$A$1;FALSE)
Which should basically mean the same. Well.. the outcome is very different:
What's even more confusing is that chaging, for example, cell I7 to "a" influences the outcome:
This is exact formula I have used, with "LUB" being "OR", and "FAŁSZ" being "FALSE":
Edit:
I forgot to stand the question. Question is: why does it happens? How do I use OR correctly in that context?
First, you need to understand how absolute and relative reference works in conditional formatting. Formula references refer to the very top left cell in the applies to range. If the formula has relative references, then for each applies to cell the cell in the formula reference shifts accordingly, if absolute - then the reference does not change. In your case, the formula =B4:G7=$A$1 is applied to cell B4, to cell C4 - =C4:H7=$A$1, to cell B5 - =B5:G8=$A$1, the same thing happens with formula =OR(B4:G7=$A$1;FALSE).
Second, the formulas =B4:G7=$A$1 and =OR(B4:G7=$A$1;FALSE) work completely differently. The first case actually compares the first cell of the range with $A$1, i.e. in the previous example =B4=$A$1, =C4=$A$1, B5=$A$1. In the second case, the range is divided into cells, they are compared with $A$1 and the results are passed to the OR function, i.e. =OR(B4:G7=$A$1;FALSE) => =OR(B4=$A$1;C4=$A$1;D4=$A$1 ... G7=$A$1;FALSE) and if even if one is TRUE, then you also get the resulting TRUE.
Consequently, we can conclude that the following formula will work correctly for you in this case:
=OR(B4=$A$1;FALSE)
Related
I've created a sequence of dates for a dynamic calender.
This works fine.
But now I want to implement a condition, using 'IF' statement, where the step of the sequence is changed based on the value in the cells in column D (starting in cell D8).
If the cell in column D contains "Y" then the step in the sequence for that specific cell must be 8 in stead of 7.
The idea is that the sequence generates a list of all Mondays of a specific year (defined in B6), but when the Monday is a holiday, the return value must be a Thuesday.
The problem is that the reference for the column (D8) doesn't change and stays on the first cell reference. It should change to D9 for the next sequence value, D10 for the 3rd sequence value, etc.
Dutch formula -
=REEKS(54;1;DATUM($B$6;1;1)-WEEKDAG(DATUM($B$6;1;1);2)+1;ALS(D8="Y";7;8))
English version formula -
=SEQUENCE(54,1,Date($B$6,1,1)-WEEKDAY(DATE($B$6,1,1),2)+1,IF(D8="Y",7,8))
Edit 04/01/2023
This is the first cell in the sequence
This is currently the second cell in the sequence, where reference to D8 needs to be D9
Now I understand your question (in my first answer, I thought you were copying your formula on another place).
There seems to be a difference between earlier Excel versions, where a formula could only have one single cell as a result. Now there are formulae (like =SEQUENCE(), whose answer spreads over different cells. All those cells contain one element of the formula result, which means that the formula itself does not change over the multi-cell result.
I'm not sure if I understand what you mean: I have copied your formula (the English one) in cell "E2" and this is what I get:
=SEQUENCE(54,1,DATE($B$6,1,1)-WEEKDAY(DATE($B$6,1,1),2)+1,IF(D8="Y",7,8))
In another cell ("G3"), this turns into (select cell "E2", press Ctrl+C, press cell "G3", press Ctrl+V):
=SEQUENCE(54,1,DATE($B$6,1,1)-WEEKDAY(DATE($B$6,1,1),2)+1,IF(F9="Y",7,8))
So, when I apply a formula to another cell (two columns further, one row further), the reference to "D8" turns into "F9" (two columns further, one row further).
The other reference ("$B$6) does not change. Obviously, because the dollarsigns prevent that value to be changed (this is exactly what absolute and relative cell references are about, as described here).
Unfortunately, I don't know what you mean when you say that your cell references don't change: the ones, who should, do, and the ones, who shouldn't, don't, which is correct behaviour.
Oh: when you enter your formula in an external tool (like Notepad or so), you paste your formula in a cell and you paste it again in another cell, Excel won't realise that the cell references need to be update, is this the problem you're having?
In order to do some calculations on averages and differences of values in columns, I've defined a name, based on a range, but it seems to be completely going berserk:
I have a cell (D13), defined as Header_First _Answer, which contains the title of the column, and I have a value (currently being 69), which contains the number of entries, called Total_Count.
I've defined the entries of that column as another name: "All_First_Answered_Dates", defined as =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (start by the first entry under Header_First_Answer, take up to 69 entries, and define a range out of this).
In cell G5, I'm using that name in order to do some calculations (calculating averages), but this seems not to work (there is a #Value error).
After second comment from Rory: G5 formula and first formula evaluation result:
Formula:
=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)
First evaluation result:
=AVERAGE(IF(ISBLANK(#Value!);TODAY();All_First_Answered_Dates) - All_Start_Dates)
Hence, my conclusion:
After some checking I've found out that this is due to the name "All_First_Answered_Dates", which seems to be interpreted one time too many (or how do I explain this):
In different cells, I've entered the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (which is exactly the meaning of "All_First_Answered_Dates"), and every time, using the Evaluate Formula feature, I see that the last but one result is correct: $D$14:$D$82. However, after that, another evaluation is done, turning this value into 43283 (in case the formula is entered in "J14"), 43300 (in case the formula is entered in "J15"), ..., and in case I enter this formula in a cell with row number lower than 14, I have the error value #Value (which explains the wrong result in cell G5).
If I simply put the formula =$D$14:$D$82 in any of the mentioned cells, then the content of some cells in column D are shown (which are dates, not values like 43283 or 43300).
It appears that declaring a range as =x:y, where x and y are formula results, is not working.
Does anybody know how I can define a range as a formula, which I can then use in order to define in a name?
I can imagine my explanation being quite complicated without an image, hence the attached screenshot. In there:
In cell J13, there is the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0).
In cell J14, there is the same formula.
In cell K14, there is the formula =$D$14:$D$82.
For completion purposes, hereby a screenshot of the name manager, containing both mentioned names (the ones, selected in the name manager):
Edit after first comment:
The idea behind the range is the following:
1. Take the first row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;1;0)
2. Take the Total_Count's row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;Total_Count;0)
3. Define a range, based on those two cells, by putting a semicolon between them.
I was not aware of the height and width features of the Offset() worksheet function. I've implemented them, which makes the formulas much easier.
Unfortunately the problem still persists.
Thanks in advance
Dominique
I've just found the answer of what was going wrong:
The formula was meant to be an array formula. Something went wrong and while trying to debug, I accidently re-formatted the formula into a normal formula (I must have pressed "ENTER" instead of "Ctrl" + "Shift" + "ENTER") at some point.
I have re-applied array formula (using "Ctrl" + "Shift" + "ENTER"), getting a formula like:
{=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)}
(mind the braces {, })
Now everything is working fine.
I have a three page work book. Pages 2 and 3 hold similar data but from different time periods (Cases Current, Cases Historic). Takes together the information from Cases Current and collates certain information using COUNTIF.
I have been trying to get a conditional format to change the text colour if the COUNTIF from Cases Current is higher or lower than a COUNTIF on the same data in the historic page. E.g.:
Cell C3 has the following formula :
'=COUNTIFS('Cases '!$D:$D,C$2,'Cases '!$C:$C,$A3) and displays the figure 7.
I have used a IF formula in a regular cell and this following does work. (In this example the COUNTIF returns 10.)
IF(C3<COUNTIFS(Compare!$D:$D,C2,Compare!$C:$C,$A3),"Lower","Higher")
I have used the same formula in Conditional Formatting but it triggers no change in font colour. I have stripped the two end conditions off the end of the IF statement as the conditional formatting is triggered on a TRUE return.
=IF(C3<COUNTIFS(Compare!$D:$D,C2,Compare!$C:$C,$A3)
This formula is incorrect for what you're attempting:
=IF(C3<COUNTIFS(Compare!$D:$D,C2,Compare!$C:$C,$A3)
It is actually an incomplete IF statement - try to copy it into a cell, and you will see that you don't have an argument for IF's "TRUE" state (which is required). Instead, you don't need an IF statement at all, just:
=C3<COUNTIFS(Compare!$D:$D,C2,Compare!$C:$C,$A3)
So this will check the value of cell C3, then check the value of the COUNTIFS function, and then check that C3 < COUNTIFS. If it is, it's a true statement, resulting in TRUE. Otherwise, it returns FALSE.
I am using a standard format if statement, in this case +if(A15="Sub Total", W15, (W15+AA15)) in cell AC15. W15 contains the formula sum(W10:W15).
The if statement results in a value in AC15 of sum(W10:W15) rather than the relative formula sum(AC10:AC15). This is important as the figures in column AC vary in subsequent iterations independently of those in column AC.
Sounds like a simple problem - but I cannot resolve.
If you reference a cell in a formula, that cell's value will be used in the formula, not its underlying formula (if any).
W15 contains the formula sum(W10:W15)
That is a circular reference. W15 cannot include its own value in the sum. Also, if you want in AC15 a formula sum(AC10:AC15) this would also be a circular reference.
Straighten out your data layout.
I am trying to avoid using VBA if that's at all possible and I most certainly think that it is!
I'm currently trying to sum up a range if a certain condition is met. My function works when the range is limited and small, but does not work when I encompass my actual desired range. Here is some snippets of code:
=SUMIF(B13:M13,P23, B15:M15)
That function currently sums from B15 to M15 if there are any matches in between B13 and M13 with P23. It works like a charm. If there are discrepancies in between B13 and M13 it will only sum that matches which is exactly what I want it to do.
I want it to cover a much broader range, so I altered my formula as follows:
=SUMIF(B13:M13:B32:M32:B51:M51,P23, B15:M15:B34:M34:B53:M53)
I want it to do the same thing as before. I want it to analyze B13:M13 as well as B32:M32 as well as B51:M51 and compare it to P23. If there are matches I want it to sum B15:M15 as well as B34:M34 as well as B53:M53. If there are non matches, I want them to be omitted as was the case in my previous function.
Can anyone tell me what's wrong with my formula?
Actually, your formula =SUMIF(B13:M13:B32:M32:B51:M51,P23, B15:M15:B34:M34:B53:M53) converts to =SUMIF(B13:M51,P23, B15:M53) (you can check it for example using "Evaluate formula" tool in the "Formulas" Ribbon or by entering in cell B18 value, euqals to P23, and another value in B20 - your formula will add value from B20 to the result). And it doesen't calculate propertly, because you have some text values in B16:M33, B35:M52
So, you can use following formula instead:
=SUMPRODUCT((B13:M13=P23)*(B15:M15)+(B32:M32=P23)*(B34:M34)+(B51:M51=P23)*(B53:M53))
Here is result of evaluating your formula (=SUMIF(B13:M13:B32:M32:B51:M51,P23, B15:M15:B34:M34:B53:M53)):