If-else statement with multiple conditions in microsoft excel - if-statement

Is there a formula in Microsoft Excel 2007 wherein I can have multiple "else" statement if a specific keyword is found in the cell that I'm calling. For example, if cell C3 contains the word "Network" it will automatically input "5" in cell B3, otherwise if it contains the word "Software", it will input "4" in cell B3 and so on. I've tried using this code below but it shows error
=IF(OR(SEARCH("Har",C5)),"6", IF(SEARCH("Soft", C5)), "7","")

This will work for your 2 examples shown
=IF(NOT(ISERROR(FIND("Network",A3))),5,IF(NOT(ISERROR(FIND("Software",A3))),4,"-"))
what if I need to find two keywords for example if cell A3 contains either "Network" or "Hardware" it will return 5
=IF(OR(NOT(ISERROR(FIND("Network",A4))),NOT(ISERROR(FIND("Software",A4)))),5,"-")

Related

How to get all cells that appear more than 5 times?

enter image description here
I have a table in OpenOffice that contains a column with region's codes (column J). Using table functions, how to get all codes that appear more than 5 times and write them in one cell?
Normally I would recommend breaking this problem down into smaller parts using helper columns. Or better yet, move the data into LibreOffice Base which can easily work with distinct values.
However, I managed to come up with a rather large formula that seems to do what you asked. Enter it as an array formula.
=TEXTJOIN(",";1;IF(COUNTIF(исходник.J$2:J$552;исходник.J2:J552)>5;IF(ROW(исходник.J2:J552)=MATCH(исходник.J2:J552;исходник.J$2:J$552;0)+ROW(J$2)-1;исходник.J2:J552;"")))
I can't test this on your actual data since your example is only an image, but let's say that there are six of both 77 and 37. Then this would show 77,37 as the result.
Here is a breakdown. Look up the functions in LibreOffice Online Help for more information.
=TEXTJOIN(",";1; — Join all results into a single cell, separated by commas.
IF(COUNTIF(исходник.J$2:J$552;исходник.J2:J552)>5; — Find codes that occur more than 5 times. This is the same as what you wrote.
IF(ROW(исходник.J2:J552)= — Compare the next result to the row number that we are currently looking at.
MATCH(исходник.J2:J552;исходник.J$2:J$552;0)+ROW(J$2)-1; — Determine the first row that has this code. We do this to get unique results instead of 6 or more of each code in the result.
исходник.J2:J552;""))) — Return the code. (Your formula simply returns 1 here, which doesn't seem to be what you want.) If it doesn't match, return an empty string rather than 0, because TEXTJOIN ignores empty strings.

Avoid duplicate code in Excel IF formula code

I want to avoid duplicate code within excel formulas. Is there a method to repeat a certain code segment?
=IF(A1=1,(A1-B2-C3),(A1-B2-C3)+1)
This would be especially useful when it comes to more complex or longer sections. But: everything must be in ONE formula in ONE cell. Thanks! :-)
EDIT: This is my current code.
=IF(ISNUMBER(SEARCH(".amp",A2)),IFERROR(MID(A2,FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))+1,SEARCH(".html",A2)-FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))-5),""),IFERROR(MID(A2,FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))+1,SEARCH(".html",A2)-FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))-1),""))
It strips the long ID number out of any URL of a specific CMS. So
FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-","")))
is probably the part which occurs more than once and should be replaced for a code which does not be that duplicate-prone.
EXAMPLE: www.domain.com/path1/path2/this-is-an-article-123-dd-123456789.html --> 1234567890
EXAMPLE: www.domain.com/path1/path2/this-is-an-article-123-dd-1234567890.amp.html ->
1234567890
EXAMPLE: www.domain.com/path1/this-is-an-article-1234567890.html ->
1234567890
In google sheets, you could use REGEXEXTRACT to get what you want:
Formula in B1:
=REGEXEXTRACT(A1,"\d{8,}")
Place the complex common sub-expression in its own cell and refer to that cell.
EDIT#1:
As an alternative, you can use a Named Formula for the sub-expression:
Named Formula
So here is another way of finding the code in Excel:
Here is the formula in Cell B1 which needs to be confirmed by pressing Ctrl+Shift+Enter, then drag it down to apply across board:
{=FILTERXML("<data><a>"&SUBSTITUTE(MID(A1,LARGE(IF(MID(A1,ROW($A$1:INDEX($A:$A,LEN(A1))),1)="-",ROW($A$1:INDEX($A:$A,LEN(A1)))),1)+1,LEN(A1)),".","</a><a>")&"</a></data>","/data/a[1]")}
For the logic behind this formula you may give a read to this article: Extract Words with FILTERXML.
Cheers :)
Ps. it seems that GoogleSheet has out performed Excel in some area already.

Formula to return value if all non-empty values are same, else return empty?

I have a Google Sheet with many (many, many) cases of the following situation:
A B C D E
1 a b1 e1
2 a
3 b2 d e2
4 a e2
Basically each row lists content (information about research papers) scraped from a different location; theoretically, the values in each row should be the same, but since some locations lacked some information, and sometimes the information differs in some minor (but possibly important) way, there isn't 100% agreement throughout.
I'd like for each cell below such a group to display one value if all the non-empty values in that column are the same and to display nothing at all if there's some disparity between the non-empty values. See row 5 below:
A B C D E
1 a b1 e1
2 a
3 b2 d e2
4 a e2
5 a d
This is basically a first programmatical clean-up to assist further manual labor (which is unavoidable).
There's an example sheet available here - the real thing would have about 18 sets of values (title, authors, ISBN, publication, URL, keywords, etc), and 270 columns (each for another publication). The orange rows at the bottom are just pasted in manually but show the values I would like to get in the blue rows via formulas.
I realize this can be done with a massive string of IFs, but... surely there must be a way to write a formula that will extract all the non-empty values from an array or group of cells, compare them with each other, and return a single value if they're all equal?
Unfortunately, I'm drawing a blank...
=IFERROR(IF(COUNTA(UNIQUE(FILTER(B2:B5, B2:B5<>"", B2:B5<>"#N/A")))>1, ,
UNIQUE(FILTER(B2:B5, B2:B5<>"", B2:B5<>"#N/A"))))
or shorter:
=IF(COUNTUNIQUE(FILTER(D2:D5, D2:D5<>"", D2:D5<>"#N/A"))>1, ,
UNIQUE(FILTER(D2:D5, D2:D5<>"", D2:D5<>"#N/A")))
Countunique should work:
=if(countunique(A1:A4)=1,sortn(A1:A4,1),"")
I've used sortn because I want to remove any empty cells from the list of values before displaying what should be the single non-empty value and that is one way of doing it (empty cells are sorted to the end so won't appear).
Edit
If the data includes #N/A's probably the shortest way to deal with them would be to use the (to me slightly obscure) function countuniqueifs
=if(countuniqueifs(A1:A4,A1:A4,"<>#N/A")=1,sortn(A1:A4,1),"")
Blank cells and #N/A's are still sorted after everything else, so I think the sortn part should still be valid.
But there is a further issue with this - if the range contains empty strings returned from a formula, the sortn part won't work properly, so would have to fall back on filtering:
=if(countuniqueifs(C1:C4,C1:C4,"<>#N/A",C1:C4,"<>")=1,filter(C1:C4,C1:C4<>"#N/A",C1:C4<>""),"")
This is surely not an optimal solution but it works
=IF(COUNTIF(A1:A7,first_non_empty_cell)=COUNTA(A1:A7),first_non_empty_cell,"")
You might consider replacing first_non_empty_cell with
LOWER(INDEX(A1:A7,MATCH(1,INDEX((A1:A7<>0),0),0)))
or with the cell containing the value you want to use for comparisons.

Sheets is treating "0" like a blank cell

I need help with what I'm sure is a simple formula that I just don't understand.
I have three columns. The first two hold my values and the third is meant to subtract them. However, when the first column is blank, I would like the third to also be blank. I have it close right now but when I type 0 in the first column, it treats that as a blank cell instead of using the 0 to give the sum.
Ex. of what I would like
expected result:
I can't seem to figure out the formula for the third column.
Yes this is a quirk that goes right back to the dawn of spreadsheet applications; in an empty worksheet the formula =A1 written anywhere other than the top left cell will evaluate to 0.
One way, in Google Sheets, is to use something like
=IF(ISBLANK(A1), ,A1 - B1)
In Microsoft Excel you need to use double quotations characters in the second argument, noting that this injects a blank string into the output.
This if statement (put in the 3rd Column) checks the first column if blank then just set cell as blank else perform the subtraction:-
=IF(A1="", "", A1-B1)

Conditional Vlook up without using VBA

I want to convert an input to desired output. Kindly help.
In the output - the columns value should start from most recent (year)
Please click this to see data
Unfortunately VLOOKUP is not able to fulfill that ask. However the INDEX-function can.
Here is a good read on how to use it:
http://fiveminutelessons.com/learn-microsoft-excel/use-index-lookup-multiple-values-list
This will work for you spreedsheet, if your input table starts at A1 without a header and your output table starts at H3 with the first ID.
You get this by copy&pasting the first column of your input table to column H and then remove duplicates.
{=IF(ISERROR(INDEX($A$1:$C$7,SMALL(IF($A$1:$A$7=$H$3,ROW($A$1:$A$7)),ROW(1:1)),3)),"",
INDEX($A$1:$C$7;SMALL(IF($A$1:$A$7=$H$3,ROW($A$1:$A$7)),ROW(1:1)),3))}
Let's look at the formula step by step:
The curly brackets tell excel that this is an array formula, the interesting part for you is: when you've inserted the formula (without curly brackets) press shift+ctrl+enter, excel will then know that this is an array formula.
'error at formula?, then blank, else formula
=IF(ISERROR(....),"",...)
When you autofill this formula you probably dont know how many instances of your lookup variable are. So when you put this formula in 4 cells, but there are only 3 entries, this bit will keep the cell blank instead of giving an error.
INDEX($A$1:$C$7,SMALL(IF($A$1:$A$7=$H$3,ROW($A$1:$A$7)),ROW(1:1)),3))
$A$1:$C$7 is your data matrix. Your IDs (in your case 125 and 501) are to be found in $A$1:$A$7. ROW(1:1) is the absolute(!) rowID, 3 the absolute(!) column id. So when you move your input table those values have to be changed.
What exactly SMALL and INDEX do are well described in the link above. (Or at least better than I could.)
Hope that clarified some parts,
Tom