excel formula non trivial nested OR - excel-formula

how to form an IF function for the following statement:
IF (1 or 2 happens) then IF 1 happens A happens and IF 2 happens B happens?

I think you are talking about nested IF statement
Stick numbers 1, 2, 3 in cells A1, A2, A3, then in Cell B1 stick the below formula and drag it down
=IF(A1=1,"A happens",IF(A1=2,"B happens","Neither A or B"))
And your results

I know this is an old problem but it seems to be left dangling because the OP
did not express himself well.
My answers is for the people whose searches bring themselves here.
The originals posters has a common problem in asking a question about Excel because they don't understand a fundamental point about excel solutions.
A cell formula can only set the value of the cell it is in using information from elsewhere in the sheet.
There is no action at a distance.
The OP idea that something can "happen" is not excel thinking.
The "happening" event has to be laid out as a set of calculations that
each produce a piece for the event. Each piece would then be put in a separate cell controlled by the if statement condition.
For example if the event was "show a schedule for the Day".
The test could be is it a Weekday or a Weekend.
Part of the schedule could be Wake up time, Breakfast Food, Clothes to Wear.
The options for Weekday/Weekend could be for each question 6am/10AM, Cereal/Eggs, and Suit/Jeans respectively.
Each item would be in its own cell displaying its result, this will take up 3 separate cells that will all depend on the day which is stored in yet another cell.
Each of the 3 results cells would have a formula that looks like this (in English not Excel):
For Wake up time:
if(Date in question is a weekday, display in this cell "6AM", otherwise display "10AM")
I do not intend to build an actual sheet out of this because my intent is to
point out how to think in excel.
To summarize: to show a complex conditional result in excel you must show each of it parts in a different cells that all depend on one common cell.

Related

Conditionally format a cell based on all of the values of a range of cells

I am trying to create an editable calendar of availabilities, wherein people can input that they are available either during the day, at night, all day, or not at all.
I would like the calendar to automatically highlight days when there is an overlap of availability - say, when everyone is free at night, or some are free all the time and one only during the day.
I can do the former by using the formula =AND(($C2:$G2)="night") - when all five people input "night", it highlights as fully available. However, my problem is with the "All the time" variable.
How would I create a conditional format that highlights cell A2 (for example) when all of the cells in range C2:G2 are filled with either "day" or "both"? So far I've gotten to =OR($C2:$G2="day",$C2:$G2="both"), but this has the problem of highlighting A2 if even just one cell in the range has the desired value. I assume I have to include an AND command here, but how exactly?
Thank you for any help :)
Screencap of calendar: Columns A and B are filled with days/dates. C1:G1 are labelled Person 1 - Person 5. Each person has filled an availability for each date, either "night", "day", "both", or "NA".
Another solution would to be using a couple COUNTIF() functions and comparing to the total, in your case 5 since you have 5 columns.
Sum the results of the two COUNTIF() functions, if they equal 5, your data is highlighted:
=COUNTIF($C2:$G2,"day") + COUNTIF($C2:$G2,"both") = 5
Essentially, if the left side of your equation is equal to the right side then it will return True.
This can be a little more portable. Only need 3 or more of the 5 cells? You could simply change to >= 3 instead of being = 5.
In the event no one is able to come up with a more elegant solution, here's one that at least would work for you. Not too bad if you only need to compare the 5 columns, could be a bit more painstaking if you have more.
=AND(OR($C2="day",$C2="both"),OR($D2="day",$D2="both"),OR($E2="day",$E2="both"),OR($F2="day",$F2="both"),OR($G2="day",$G2="both"))
The And() function, as you are likely already aware, requires that each and every value within it returns a True value to have it output a value of True.

COUNTIFS ignoring rows based on values in row

I have been struggling with these two problems for the better part of the day. Please see this link to an example: https://docs.google.com/spreadsheets/d/1odU7oqc-WviLzQcghkbYbQG-4DC70-Q_hszb22Chljw/edit?usp=sharing
This is a simplified document I use to see which lecturer (name) has has added which of the 5 documents (on the right) to an online learning environment (one row for each course). The courses can be given in semester 1, 2, or in both. I want to use this document to automatically highlight a name if any of the five boxes on the right is empty if the semester I want to check (Cell D1) is similar to Column E. Furthermore, only the first time a name appears in red, should the e-mail appear so as well.
For this, I of course use conditional formatting (please see those formulas, also pasted in column M (range column C and D) and N (Range column D). N is the white conditional formatting overruling M, in which a N="TRUE" means it is whitened out).
Example 1 (Ans) shows how I intend the programme to work. The first instance shows shows both the name and e-mail in red, later instances do too unless the semester is not similar or all boxes on the right are ticked.
Example 2 (Bertrand) shows the first problem. If the first instance of a red name and e-mail occurs in a semester 'both', the second time the name should be red the e-mail does so as well. This keep occurring until a semester is similar to Cell D1, after which it is normal again.
Example 3 (Carel) shows the second problem. If the first instance in which a certain lecturer occurs all boxes on the right are ticked, the second time he occurs but does not tick all boxes his name shows in red but his e-mail doesn't.
I think problem 1 (example 2) is solved if I can get 'both' to somehow mean both 1 and 2, but I don't know how.
I think problem 2 (example 3) is solved if I can get COUNTIFS to ignore the rows is which all five boxes are ticked.
However, I have no clue how to do this. Is anyone able to help me with either (but ideally both) problems?
Thank you in advance!
I'm not entirely sure, but I think I've understood what you need.
For the first part (where a lecturer has less than all 5 subjects containing 'x' AND where E is either the value of cell D1 or the value of 'both'), try this:
Delete both of your existing conditional formatting rules.
Create a new conditional formatting rule for range = C4:C21 (or perhaps further down your sheet to row 977), with a custom formula of:
=AND(COUNTIF($G4:$K4,"x")<5,or($E4=$D$1,$E4="both"))
The style for the rule should have a red background.
For the second part (updated), this is a bit tricker with conditional formatting but I can offer a solution determined by the value of cells, like you had.
Delete the contents of cells M4:N21 (21 being where you have a formula in the furthest cell).
In cell M4, add the following formula:
=arrayformula(if(iferror(if(ifs(E4:E=$D$1,1,E4:E="both",1)+if(G4:G&H4:H&I4:I&J4:J&K4:K <>"xxxxx",1,)=2,D4:D,),)<>"",countifs(iferror(if(ifs(E4:E=$D$1,1,E4:E="both",1)+if(G4:G&H4:H&I4:I&J4:J&K4:K <>"xxxxx",1,)=2,D4:D,),),iferror(if(ifs(E4:E=$D$1,1,E4:E="both",1)+if(G4:G&H4:H&I4:I&J4:J&K4:K <>"xxxxx",1,)=2,D4:D,),),row($E4:$E),"<="&row($E4:$E))=1,))
It might seem a little complex, but it's done this way to use the functions that are compatible with ARRAYFORMULA so that it will keep working down the sheet as far as you have values in rows.
Now create a new conditional formatting rule for range = D4:D21 (or perhaps further down your sheet to row 977), with a custom formula of:
=$M4=true
The style for the rule should have a red background.

Excel: Cell displays different value than it is linked to (iterative calculation)

I'm building an Excel model using iterative calculations.
The problem results in the yellow cells shown below:
One cell is linked to another and displays a different value than it should.
The bottom value (29.4%) is the correct one, so of course I would like Excel to actually use that one.
When clicking F9 (third picture) one can see that the cell value should technically be correct.
Please let me know if you need any further information as I'm new to SO. Thanks in advance!
Using circular references in Excel requires planning of the layout of the model, in order to get a stable result. And the calculation order is not the same with iterative calculations. One consequence is that if the cell referring to the "iterative cell" is above, it may show the result of the previous iteration.
Here is a very simple model demonstrating that:
A14: 1
A15: =A15 + A14
B13: =A15
B17: =A15
The following shows the results of four single iterations, one at a time. You will see that B13 is displaying the results of the previous iteration; whereas B17 displays the result of the last iteration
If I recall correctly, with iterations, calculations proceed by worksheet in alphabetical order (not sure if that refers to codename or sheetname), and on a worksheet, from left to right and top to bottom.

I wish this worked... =if(C16>"0",((B16*E16)-40),D16=B16)

Theoretical code, I suppose. Been dreaming about really getting into Google Sheets lately and finally decided to ask my mother about it. 20 minutes into Google sheets and I had already written more advanced calculations than she ever had in 20 years.
=if(C16>"0",((B16*E16)-40),D16=B16)
I'm frustrated. I want to create an if statement which poses the question
(comparing various jobs to be filled out like a questionnaire, filling in from B, then continue right, C, D,~)
whether C16 is greater than 0. If not, then D16 should be equal to B16. I want to write this formula in a separate cell, to allow the questionnaire to still be filled out. If I slap this formula in D16, then it makes everything messy.
I tried offset, but that still display the answer within the cell i wrote the formula in.
Let's put it this way. The cell I want the formula to be in is the command centre, and I want it to reflect/direct number at one cell and show them in another.
You have a number of issues.
I'm afraid your "20 minutes of learning" doesn't have you as "advanced" as you've convinced yourself and you might owe Mum an apology. :-)
Formulas do not change other cells
A formula returns it's result in the cell in which is is placed. Period. Offset does not move the result; it offsets the a cell that the formula is referencing.
"Double quotation marks" are a text qualifier
Quotation marks are a text qualifier meaning anything enclosed by double quotes is treated as text. This causes a problem for you because you need the 0 to be a number so you can compare it to other numbers (assuming C16 contains a number).
D16=B16 is a comparison
This is like saying "Does the value in cell B16 match the value in cell D16'?" and returns eitherTRUEorFALSE`. Nothing else.
Also please review the posting policies for this site.

Excel: Can an address within a cell be used as part of another cell address?

I keep thinking there must be a function that allows an address within a cell to be used as a variable within another cell address. For the types of sheets I'm creating it would make my life so much easier.
For the purposes of example, the function I seek is hypothetically called "THING" below:
Sheet1 Daily Menus
MONDAY MENU
Items: Helper Column Nutritional Data Results
A B C
1 =Sheet2!A35 =THING(A1,row=35) =INDIRECT("Sheet3!G"&B1) =Sheet3!G35
2 =Sheet2!A247 =THING(A2,row=247) =INDIRECT("Sheet3!G"&B2) =Sheet3!G247
3 =Sheet2!A989 =THING(A3,row=989) =INDIRECT("Sheet3!G"&B3) =Sheet3!G989
TUESDAY MENU
101 =Sheet2!A613 =THING(A101,row=613) =INDIRECT("Sheet3!G"&B101) =Sheet3!G613
The bottom line is:
In a complex spreadsheet (10 pages, each with hundreds of rows and columns), I want to manipulate the addresses by altering only the data in column A on page 1.
This would also allow me to easily copy column B down for hundreds of rows. The type of function in column B may also be required in columns C, D, E... for dozens or hundreds of columns.
Right now I'm typing in each needed address manually, or a very long function using the address. If anything changes in column A then I have to go back and retype these long functions... and often I find that I've made a typo with all that typing...
You seem to have as your starting point formula =Sheet2!A35 in cell A1.
What you have to do is:
Get the formula as a string.
For this you can use either XL4 macros, VBA, or FormulaText (in Excel 2013 or later), see this.
Extract the row number from the string.
For this you an use VBA (very easy), or a formula to find the rightmost letter/$ and keep the substring to its right.
Use the previous answer, as you already incorporated in your question.
Answer to the first version of the question
I will split the formula you are looking for in two steps.
In cell B1 you can enter ="Sheet2!"&"X"&TEXT(A1,"0").
This will produce the result Sheet2!X25.
Then in cell C1 you can enter =INDIRECT(B1).
This will bring into cell C1 the contents of cell Sheet2!X25.
Notes:
You can copy the formula downwards as you need.
When copying into other columns, take care of relative/absolute indexing.
You could use a single formula (no helper column) in B1: =INDIRECT("Sheet2!"&"X"&TEXT(A1,"0")).
Both Sheet2 and (column) X could be replaced by suitable formulas if you want them not be hardcoded.
Formula in B1 can almost certainly be replaced by
="Sheet2!"&"X"&A1.
NB: A long time time ago, under circumstances I do not recall now, I found I needed to use TEXT; YMMV.

Resources