Excel: How to nest if and count if statements? - excel-formula

I want to check if cell O3 is contained in list A7:A11, and if so, return cell G2. I'm using the following formula to do this, and it works:
=IF(COUNTIF($A$7:$A$11,"*"&O3&"*"),$G$2,"")
However, I want to add another of these, to check multiple lists e.g.
=IF(COUNTIF($A$7:$A$11,"*"&O3&"*"),$G$2,"") , IF(COUNTIF($A$12:$A$14,"*"&O3&"*"),$G$7,"")
but this does not work (I can't successfully nest these statements, I tried using OR but this also failed)
So, I want to check if cell 03 is contained in list A7:A11 and if so, return G2, but also, if cell 03 is contained in list A12:A14, return G7 and so forth.

Related

Assign values by matching two lists in excel

I have these two list and I am trying to assign values i.e 11,22,33 to the second list that matches values with the first list.
So, for examples in the second list if its "Industrials" it would take value of 11, "Resources" would take value of 33 and so on.
I have tried index match but I believe it won't work in this case. Any help or ideas would be great.
So you may try using any one of the following formulas as shown in the image below
APPROACH ONE - FORMULA USED IN CELL E2
=INDEX($B$2:$B$8,MATCH(LEFT($D2,3)&"*",$A$2:$A$8,0))
APPROACH TWO - FORMULA USED IN CELL F2 (O365 & EXCEL 2021)
=XLOOKUP(LEFT($D2,3)&"*",$A$2:$A$8,$B$2:$B$8,,2)
APPROACH THREE - FORMULA USED IN CELL G2
=VLOOKUP(LEFT($D2,3)&"*",$A$2:$B$8,2,0)
APPROACH FOUR - FORMULA USED IN CELL H2
=LOOKUP(2,1/(LEFT(D2,3)=LEFT($A$2:$A$8,3)),$B$2:$B$8)

Excel Output based on multiple input

I have multiple input values in excel that should be used to dynamically generate an output in a cell.
For example in cell B1:B15 I have 15 checkboxes, and in cell A1 I have a dropdown menu with multiple values. Now I want to take the value of cell A1 and then based on the checked boxes in B1:B15 I want to generate an output (a notition with an image). As you can imagine, there's quite a lot of possible ways in this 'graph'. What would be the easiest way to implement such a thing in excel, in such a manner that it is easy to expand upon?
So for example:
If (a1=="wood" and (b1==checked, b2==checked, b5==checked), "Output1")
If (a1=="wood" and (b1==checked, b5==checked, b7==checked), "Output2")
... etc.
I don't know of any way to manipulate images in excel just using formulas.
That being said, I think there might be a way to get a result similar to what you are looking for.
If you create a 2 column table of cells (I'm using c2:d5), first column checks column B for the specifics you want (ex: c2 will look at cells B1, B2, B3, and return "True" if they are all "Checked"), then all you have to do is create an output cell that says =vlookup("True",c2:d5,2,false), then it will return what you put in column d next to the check in column c.
If you want a default option if none of the conditions work out, put "True" on the last line of the table, instead of another condition. Vlookup finds the first matching condition, so as long as its the last option, it will only be found if none of the rest match "True".
if you want this to happen only if A1 = "Wood", then put a If statement around it. (=IF(A1 = "Wood", Vlookup(), [insert what you want if its not equal to "wood"]))
If you want a physical change to the cell you typed "wood" into, you can use conditional formatting: create a custom format, choose the format, type the formula as a true/false if statement. (There may be other ways to get it to work, but I don't know of any other way to make a conditional format), EX: =IF(AND($A$1="Wood",vlookup("True",c2:d5,2,false)=[result]),TRUE,FALSE)

Excel formula to look up for several specific words and if found save specific text to another column

So here is what I'm trying to do:
=
IF(RC[-7]="","",
IF(ISNUMBER(SEARCH("*flower*",A1)),"flowers are beautiful",
IF(ISNUMBER(SEARCH("*car*",A1)),"car is big",
IF(ISNUMBER(SEARCH("*tree*",A1)),"tree is green",
"Misc"))))
So IF "flower" is found in A1, then in B1 add "flowers are beautiful" AND IF "car" is found in A1 then in B1 ADDITIONALLY add "car is big" etc...
How can I achieve this, I wrote this formula but it works for one find only and it stops... how can I use "AND"..? Thank you
Basically to get your desired output, instead of nesting each IF statement within each other, you need to write them separately and combine the output.
You can use TextJoin to do that. Check the formula below:
=TEXTJOIN(", ",TRUE,
IF(COUNTIF(A1,"*car*")>0,"Cars are big",""),
IF(COUNTIF(A1,"*flowers*")>0,"Flowers are beautiful",""),
IF(COUNTIF(A1,"*tree*")>0,"Trees are Green","")
)
Here each condition is evaluated separately and all of the results are joined into one text string. The TRUE in the formula denotes if you want to ignore empty values.
Below is an example of the output:
Not sure what you really want but a much easier method to control the lists and get what you want is vlookup() like so:
The vlookup() in cell B1 and dragged down is:
=VLOOKUP(A1,$E$1:$F$4,2,0)
Cells E1 to F4 have the lists, change the range in vlookup if you add to them.
And if you want multiple answers in the one cell, then:
=iferror(VLOOKUP("flower",$E$1:$F$4,2,0),"")&", "&iferror(VLOOKUP("car",$E$1:$F$4,2,0),"")&", "&iferror(VLOOKUP("tree",$E$1:$F$4,2,0),"")
As it appears I did not get part of your question originally.

Return individual cell values from a wildcard search against a range into individual cells using Excel

so I've been trying to work out this problem in Excel (Office 2016, Mac El Capitan, latest updates installed) but have failed so far.
In essence, I would like to search a range of cells (in this case A2:A9) for a partial keyword (A2). Hence all cells that match this criterium should then appear in the result range (E2:E9). I already struggle with this, as I'm only able to return a single result (e.g. one row entry in E2). I have attempted this with INDEX and MATCH but have failed so far.
After this, I would then look-up the corresponding quantity in range B2:B9 using vlookup, this works for now.
The final, desired outcome is attached as an image.
Thanks a lot for your help.
Apply the formula below to E2 and copy down as far as needed.
=IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW(A:A)/ISNUMBER(SEARCH($C$2,A:A)),ROW(A1))),"no more entries")
in F2 use the following formula and copy down as required as well
=SUMIF(A:A,E2,B:B)
A few caveats.
Since the first formula is performing array like calculations inside the aggregate function, full column references should be avoided. Change A:A to $A$2:$A$9or whatever your range is.
Column A is assumed to be full of unique names
The search is not case sensitive. If you need it to be change SEARCH to FIND
If you do not want to see "no more entries" change it to ""
In Cell E2 enter the following formula
=IFERROR(INDEX($A$2:$A$9,SMALL(IF(ISNUMBER(SEARCH($C$2,$A$2:$A$9)),ROW($A$2:$A$9)-1),ROW(1:1))),"")
This is an array formula so commit it by pressing Ctrl+Shift+Enter. Drag/Copy down as required.
Then to get corresponding quantity enter following formula in Cell F2
=INDEX($B$2:$B$9,MATCH(E2,$A$2:$A$9,0))
Drag/Copy down as required. See image for reference.
Note: SEARCH function is case-insensitive. If you are looking for a case sensitive match, use FIND function.

One to many relationship to fetch values in an alternate rows

I am trying to fetch dates from sheet1 with common ID (there are multiple occurrences in sheet1) using an array formula in a cell (then dragging it to the right side to have all the dates belong to specific ID):
=IF(COLUMNS($E2:E2)<=$D2,INDEX(Sheet1!$B$2:$B$13,SMALL(IF(Sheet1!$A$2:$A$13=Sheet2!$A2,
ROW(Sheet1!$A$2:$A$13)-ROW(Sheet1!$A$2)+1),COLUMNS($E2:E2))),"")
But, whenever I try to insert one column (for counting purposes) in b/w the columns, this formula doesn't work. I can't figure out the issue, would really appreciate the help?
Thank you.
Assuming that your first formula is in E2, and that the cells in row 2 of any newly-inserted columns will always be blank, replace the two instances of:
COLUMNS($E2:E2)
in your formula in E2 with:
COUNT(1/LEN($D2:D2))
As a way of explanation, take the formula in F2, for which this part will be:
COUNT(1/LEN($D2:E2))
(The only part having changed naturally being the end range reference.)
And let's assume that 3 new columns are inserted to the left of column E, which means that E2, F2 and G2 will now be blank, H2 will contain the entry which was previously in E2, and, for the formula in I2, the above part will now be:
COUNT(1/LEN($D2:H2))
Clearly we wish this part to continue to give 2, since this cell should still represent the second of our returns.
Using LEN is a rigorous way to determine whether a cell is empty or not. Other functions are also available for this purpose, though may give incorrect results depending upon whether the blanks in that range are "genuine" blanks or the null string "" as a result of formulas in those cells.
If a cell is empty, it has a length of 0. Hence, in this example, the above resolves to:
COUNT(1/{1,0,0,0,2})
(Where I've made some random assumptions about the lengths of the strings in cells D2 and H2.)
There are many ways to determine how many non-zeroes there are in an array. SUMPRODUCT would be one; I chose another, the logic being that the above becomes, after reciprocation with unity:
COUNT({1,#DIV/0!,#DIV/0!,#DIV/0!,0.5})
and, since COUNT ignores any errors in the range passed to it, the above resolves to 2, as desired.
Regards

Resources