Dependent cell value with multiple conditions in excel - excel

I was hoping someone could lead me in right direction here.
Basically I am looking for a formula or VBA code to change the cell A1 value depending on multiple different conditions. The conditions are different name ranges ( in form of drop down list ) in different worksheets. So for example here are the 3 different conditions:
If the NameRange1 in sheet1 = “yes” then cell A1 = A otherwise do nothing
If NameRange2 in Sheet2 = 2 Then A1 = B otherwise A1 = C
If none of those conditions are meet then A1 = D
I am new to Excel and I know it’s quite messy but I was thinking of nested if statements with first two conditions nested inside true statement and last condition in false?
=IF(A1="",IF(condition1,IF(condition2),condition3))
Any help would be appreciated

From your comment, looks like this will work:
=IF(nameRange1="yes","A",IF(nameRange2="red","B",IF(nameRange2="black","C","D")))
If that is not exactly what you need, you can at least see the IF embedding pattern and adjust for your needs.

Related

Comparing two columns and highlighting if the specified value is not available

I have two columns A and B, If A Column have the specific value "High" then the corresponding cell in B Column should contain the Date (dd/mm/yyyy)value otherwise if date value is not available the cell should be highlighted as Red. I am new to this macro and I am not able to find the logic for this.
Sorry this isn't a comment, but I don't have sufficient rep.
I'm a little unclear how dates are populated in column B. Is this something we can take as given or are you assigning dates somehow? It might help if you could share a bit more about the structure of the sheet, maybe some "dummy data"?
That said, this sounds like a straightforward case of loops + conditional statements. I doubt this will work for you out of the box, but you could try nested For loops over columns A and B à la:
For Each cell in Range("A:A")
If cell.Value = "High" Then
If IsEmpty(Range("B"&cell.Row)) Then 'IsEmpty tests whether the cell is empty, you may need to change this if the cell has some other value in it
Range("B"&cell.Row).Interior.Color = 255 '255 corresponds to the color red
End If
End If
Next cell
I agree with Pᴇʜ though, you don't actually need VBA for this at all. You can apply conditional formatting using a formula for the rule and then use a formula like this for the cells in column B:
=IF(A2="High",IF(ISBLANK(B2),TRUE,FALSE),FALSE)
Then just make sure you apply the formula to all the rows you care about.

excel formula to give the priority to a value from a range of values in a column

This is probably a simple fix (although me thinking this, means it probably isn't), so I apologize in advance if this is mere child's play.
In an excel sheet I am working on, I have a range (for the sake of this example is B1:B10) which can contain one of 5 variables (not including blanks) - OG, D, L, PP or C.
I require a formula in another cell to review the range in question and output a value based on the following rules in this priority:
If OG appears anywhere in the column, regardless of other inputs, display OG;
If D and L and/or PP and/or C appear in the column, display OG;
If only D appears in the column, display D;
If only PP appears in the column, display PP;
If only L appears in the column, display L;
If only C appears in the column, display C; and
If all cells within the column are blank, display blank
For rules 1-6, any blank cells within the column should not be considered. It is only where all cells are blank, i.e. rule 7, that this should be considered.
I have tried IF formulas but have found these only consider a single cell.
I've tried searching everywhere and can't find anything on this (although this is probably down to me not phrasing my question/searches correctly).
Any help would be much appreciated. Thanks in advance!
Use an 'if' formula, but for your condition, Use 'MATCH': for eg, for checking the first case:
=IF(MATCH("OG",$B$1:$B$10,0), "OG", "FALSE")
The above formula will put "OG" if it's in any of the cells, else "FALSE".
In a similar way, change all your logic, but set the conditions to use match to see if they exist somewhere in the column
Here is a possible solution. For your 6 first tests, you type each of these formulas in a cell (I did it from D1 to D6) :
Test 1 (D1)
=IF(COUNTIF(B1:B10;"OG");"OG";"")
Test 2 (D2)
=IF(AND(COUNTIF(B1:B10;"D");OR(COUNTIF(B1:B10;"L");COUNTIF(B1:B10;"C");COUNTIF(B1:B10;"C";"")));"OG";"")
Test 3 (D3)
=IF(COUNTIF(B1:B10;"D")=DCOUNTA(B1:B10);"D";"")
Do the same for test 4 to 6 by replacing "D" by "P","L","C".
Now your target cell :
=IF(D7="empty";"";INDEX(D1:D7;MATCH(TRUE;INDEX((D1:D7<>"");0);0)))
This last cell will simply show the first non empty value of your test cells.
The last test is kind of implicit.
I hope I got your tests right, let me know if not.
EDIT : Sorry for the numerous editings, my Office isn't in English, that's a pain to translate the formulas. They should be working now.
EDIT 2 : Your last test is not implicit and there is a possibility that last cell show "NA". So you should add this to D7 :
=IF(COUNT(B1:B10)=0;"empty";"*A value to show if all tests didn't pass*")
Also now your target cell has D7 in its formula's range.
I feel condition 2 little confusing, Do you mean D is mandatory and other (L,PP,C) are option to result "OG" ?
What should be the result if we have multiple input of (L,PP,C) in the range ? Should it be BLANK?
I came up with this formula if D is mandatory in condition 2 and formula will return Blank if only other 3 inputs are there except "OG" and "D"
Formula: =IF(COUNTIF(B1:B10,"OG")>0,"OG",IF(AND(COUNTIF(B1:B10,"D")>0,SUM(COUNTIF(B1:B10,"D"),COUNTIF(B1:B10,"L"),COUNTIF(B1:B10,"PP"),COUNTIF(B1:B10,"C"))>1),"OG",IF(COUNTIF(B1:B10,"D")=COUNTA(B1:B10),"D",IF(COUNTIF(B1:B10,"L")=COUNTA(B1:B10),"L",IF(COUNTIF(B1:B10,"PP")=COUNTA(B1:B10),"PP",IF(COUNTIF(B1:B10,"C")=COUNTA(B1:B10),"C",""))))))
First Condition:
Condition 2:
Condition 3:
Condition 4:
Condition 5:If there is no "OG" or "D" in the array formula returns Blank.

Additional formula needed in IF statement

I currently have a large nested IF statement that uses a helper cell (C1) to dictate which formula to utilize based on numbers 1,2,3,5 & 6. Specifically, one IF statement within the larger nested IF statement needs to be updated for instances when there is a blank cell in column A. Here is how my workbook is setup:
Data Tab
Bonus Tab
Summary Tab
This is my current formula in Column B:
=IF(Data!$C$1=2,IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$3+Data!$B$2)
What I am looking for is when cells in column A are blank, than the corresponding cell in Column B would be 0. Again, the formula above has to remain in the =IF(Data!$C$1=2, format since it is part of a larger nested IF statement.
Answer I am seeking:
Thank you for looking!
Try this:
=IF(Summary!A2="",0,IF(Data!$C$1=2,IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$3+Data!$B$2))
How about adding an IF in there like this?
=IF(Data!$C$1=2,
IF(LEN(Summary!A2)>0,1,0)*
(IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$3 + Data!$B$2))
or like this
=IF(Data!$C$1=2,
IF(LEN(Summary!A2)>0,
IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$3 + Data!$B$,
0))
What about:
=IF(AND($C$1=2,LEN(A2)>0),IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$3+Data!$B$2)
I realise this gives you FALSE rather than 0 at the end, but I don't know what the rest of your 7 IF statements look like.
EDIT
Based on #AlexisOlson 's comment:
=1*IF(AND($C$1=2,LEN(A2)>0),IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$3+Data!$B$2)
This now returns 0 when Column A is blank, as required.

Using nested if functions

I am new to using nested if functions in excel. I would like to find out what the correct functions for my excel spreadsheet.
if the pH is <7.35 and the PaCO2 is >6.00, or if the WOB is documented as a yes. I would like to the cell to return a yes response and if not the cell should return a no response.
if 6 columns in my spreadsheet all have yes responses eg a1,b1,c1,d1,e1,f1, i would like the cell in the 7th column i.e. g1 to return a yes response. however if any cell in a1,b1,c1,d1,e1,f1 has either a no , unknown or blank response , g1 should return a no response.
I would be grateful if someone could help me with this by tomorrow - as it is for a work project. Thank you
Lets assume question 1 in on one sheet and question 2 is on another for sake of example. Simply transpose to your case:
If pH is in column A, PaCO2 is in column B, and WOB is in column C, your formula would look like this =IF(OR(AND(A1<7.35,B1>6),C1="YES"),"YES","NO") and paste this in the desired column on row 1. You can copy this down for all applicable rows.
For your second enquiry, I wouldn't use a nested if statement as it restricts you to only the 6 cells you have listed. The following formula will work for as many cells as you like =IFERROR(INDEX(A1:F1,MATCH("NO",A1:F1,0)),"YES"). In this case, you would simply expand your column set for both instances of A1:F1
The nested If statements would look like this (if you choose to go that direction): =IF(A1="NO","NO",IF(B1="NO","NO",IF(C1="NO","NO",IF(D1="NO","NO",IF(E1="NO","NO",IF(F1="NO","NO","YES"))))))

Excel Conditional Formatting, Referencing 2 cells to the Right with conditions

I have a list of students who are between the ages of 3 and 5. lets say column A has the code, Column D has the childs age & Column F has their age group (3-5) If their age exceeds the age group then the Cell in column A will highlight Red. I am just not sure how to write this code correctly, all of the combinations i have tried come up with an error or just don't do anything.
IF(OFFSET(INDIRECT(ADDRESS(ROW(),COLUMN())),0,7)="3-5" & (OFFSET(INDIRECT(ADDRESS(ROW(),COLUMN())),0,4)>5 {THEN FILL CELL RED} {ELSE NO FILL}
In the first part of the statement you are checking whether the cell 7 columns across = "3-5". You don't need to use offset for this, you can just reference the cell 7 across directly.
So if you're applying the conditional formatting to A1 that part of the formula would just be =IF(H1="3-5",{then},{else}).
If you just want TRUE or FALSE as the answer you don't need the IF statement, so this shortens to: =H1="3-5",
If you're applying the conditional formatting to a range instead of just an individual cell, say A1:B10, then you write the formula for the cell in the top left of the that range. So for A1:B10 you would still you the same formulae as above.
For the second part of the statement, using the same logic as above, you get: =E1>5
To check both statements together you need to wrap them in the =AND() function, giving you this as the final formula for your conditional formatting:
=AND(H1="3-5",E1>5)
By using the AND function I can achieve the desired result without cell references moving if a cell is relocated.
=AND(OFFSET(INDIRECT(ADDRESS(ROW(),COLUMN())),0,7)="3-5yo",OFFSET(INDIRECT(ADDRESS(ROW(),COLUMN())),0,4)>5)

Resources