Excel concatenate with IF statement - excel

What I am trying to do is concatenate two cells, then check that concatenated value against a column of values, and put an X in a cell if such a value exists. The following equation is what I'm using:
{=IF(CONCATENATE(A2, " ", B2) = 'MasterList'!$C:$C, "x", "")}
Column A is the name of the software and Column B the version number (A="Microsoft .NET Framework 4.5.1", B="4.5.50938", for example). I know that this concatenated value exists on the MasterList worksheet so I don't understand why I'm not getting the answer I expect.
Gurus, what's my flaw here?

The fastest comparison/lookup on the worksheet is a MATCH function. If you have a long column to put this formula into you could try,
=IF(ISNUMBER(MATCH(CONCATENATE(A2, " ", B2), 'MasterList'!$C:$C, 0)), "x", "")
Fill down as necessary.

It seams that you select the entire column C on yout MasterListSheet. Don't you mean just one cell? Like:
=IF(CONCATENATE(A2, " ", B2) = 'MasterList'!$C1, "x", "")
or try to : =IF(CONCATENATE(A2, " ", B2) = MasterList.!$C1, "x", "") (on open Office)
Best thing is instead of you write the Sheet name, let Excel do it for you by editing the formula, remove the sheet name and then with a mouse click navigate to the desired area.

I just want to say that before seeing this question, I had no idea what array formulas were.
I have the following working example:
Sheet1:
A1: Microsoft .NET Framework 4.5.1
B1: 4.5.50938
// press control-shift-enter after typing formula
C4: =IF(CONCATENATE(A1," ",B1)=Sheet2!$A:$A,"YAY","NAY")
Sheet2:
A1: Microsoft .NET Framework 4.5.1 4.5.50938
Not sure what the issue is with your spreadsheet. Do the values in MasterList!$C:$C actually correspond to what you expect as the result of the concatenation?

This is not a valid array formula. The LHS is a single cell while the RHS is an array. What it actually does is compare the concatenation to all cells of columns C in MasterList.
You either need to make it a valid array formula or a normal formula. I recommend the second solution.
For the first solution, it should be:
{=IF(CONCATENATE(A:A, " ",B:B ) ='MasterList'!$C:$C, "x", "")}
However, this will be very slow because it will compute and concatenate two full columns, and moreover you will have to select your whole range where you want to calculate it (a full columns) then press Ctrl+Shift+Enter.
You can make it a simple formula in on cell then copy/paste along your column. Formula for C2:
=IF(CONCATENATE(A2, " ", B2) = 'MasterList'!$C2, "x", "")

Related

How to do an if statement

This question is linked to Formula to remove every middle name in a cell in Excel.
I basically want to make an if else statement in excel. So the IFchecks if the cell is equal to "Gian" OR"Pier", if the condition is confirmed the formula proceeds to use this other formula
=IFERROR(LEFT(A2,FIND(" ",A2)-1),A2)
Sorry guys idk how to do it in an excel way. I can show you in for example in a Java or C way.
if(A2=="Pier" || A2=="Gian")
=IFERROR(LEFT(A2,FIND(" ",A2)-1),A2) \\the excel formula that deletes every second/third name if the cell
if formula in excel that checks a condition and if its verified it proceeds to use another excel formula
You could try the following as per your Excel Versions
• Formula used in cell B2
=IF(OR(TEXTBEFORE(A2&" "," ")={"Pier","Gian"}),A2,TEXTBEFORE(A2&" "," "))
Or, in cell C2
=IF(OR(LEFT(A2&" ",FIND(" ",A2&" ")-1)={"Pier","Gian"}),A2,LEFT(A2&" ",FIND(" ",A2&" ")-1))
Just adding the use of LET() which makes it simpler,
• Formula used in cell B2
=LET(x,TEXTBEFORE(A2&" "," "),IF(OR(x={"Pier","Gian"}),A2,x))
Or, Formula used in cell C2
=LET(x,LEFT(A2&" ",FIND(" ",A2&" ")-1),IF(OR(x={"Pier","Gian"}),A2,x))
Using MAP() to Spill as one dynamic array formula but the logic remains same.
• Formula used in cell D2
=MAP(A2:A6,LAMBDA(m,
LET(x,TEXTBEFORE(m&" "," "),
IF(OR(x={"Pier","Gian"}),m,x))))
you have to use the AND(...) and OR(..) for chaining logical conditions.
Here's an example

index, small, subtotal, returning multiple matches from filter cell

I have the following index/match lookup only in visible cell working properly, however....
=IFERROR(INDEX($F$2:$F$500,SMALL(IF(((SUBTOTAL(3,OFFSET($G$2:$G$500,ROW($G$2:$G$500)-MIN(ROW($G$2:$G$500)),,1))>0)*($K$517=$G$2:$G$500)),ROW($G$2:$G$500)-MIN(ROW($G$2:$G$500))+1),1)),"")
Column F is what I want returning, Column G has the criteria value in them. K517 is the lookup value.
Now from Column F there are more then 1 results to be return. I want to use the & and string all the return results in a single cell. How should I approach?
To clarify, Say I want to look up "Adam" (K517) it returned the first value "red" from Column F. However, there are also "yellow and Blue" that matches "Adam". So I want in a cell to display (Red, yellow, blue) based on the filtered cell. Hope that make sense, thank you in advance.
James,
I wouldn't do it this way but if you have to use a formula and you have a known maximum number of returned values you could concatenate the 1st, 2nd, 3rd etc. matches e.g. with 3 results (don't forget CTRL + SHFT + ENTER). The Err test makes sure you don't end up with extraneous commas.
=IF(IFERROR(INDEX($F$2:$F500,MATCH($K$517,$G$2:$G500,0)),"Err") = "Err","",
INDEX($F2:$F500,MATCH($K$517,$G$2:$G500,0))) &
IF(IFERROR(INDEX($F2:$F500,SMALL(IF($G$2:$G500=$K$517,ROW($G$2:$G500)-
MIN(ROW($G$2:$G500))+2),2)),"Err")="Err","Err", ", " &
INDEX($F2:$F500,SMALL(IF($G$2:$G500=$K$517,ROW($G$2:$G500)-
MIN(ROW($G$2:$G500))+2),2))) &
IF(IFERROR(INDEX($F2:$F500,SMALL(IF($G$2:$G500=$K$517,ROW($G$2:$G500)-
MIN(ROW($G$2:$G500))+2),2)),"Err")="Err","", ", " &
INDEX($F2:$F500,SMALL(IF($G$2:$G500=$K$517,ROW($G$2:$G500)-
MIN(ROW($G$2:$G500))+2),3)))
If you have TEXTJOIN function available you can use this array formula to return all matches in one cell
=TEXTJOIN(", ",1,INDEX($F$2:$F$500,N(IF(SUBTOTAL(3,OFFSET($G$2:$G$500,ROW($G$2:$G$500)-MIN(ROW($G$2:$G$500)),0,1)),IF($K$517=$G$2:$G$500,ROW($G$2:$G$500)-MIN(ROW($G$2:$G$500))+1)))))
confirmed with CTRL+SHIFT+ENTER
....or with this version you can get one result per cell e.g. in K2 copied down until you get blanks
=IFERROR(INDEX($F$2:$F$500,SMALL(IF(SUBTOTAL(3,OFFSET($G$2:$G$500,ROW($G$2:$G$500)-MIN(ROW($G$2:$G$500)),0,1)),IF($K$517=$G$2:$G$500,ROW($G$2:$G$500)-MIN(ROW($G$2:$G$500))+1)),ROWS(K$2:K2))),"")
also needs CTRL+SHIFT+ENTER

Conditional LEFT Excel formula (or VBA?) based on formula results?

I have in Column C2, formula results which I need to perform LEFT on in order to trim the cell formula value
The formula result MUST have one of the following (. OR _ OR -) in answer
If one of the above exists in the cell , then LEFT(C2,FIND("the_variable_in_the_formula_answer),C2)-1)
My VBA isn't the best, but I think I could use
variable = Left(Sheet1.[C2],InStr(Sheet1.[C2],".")-1)
I don't know how to make the .(period) , _(underscore) OR -(hyphen) a variable to look for
Try this formula at row two and fill down the column:
=IFERROR(LEFT(Sheet1!C2, AGGREGATE(15,6,SEARCH({".","-","_"},Sheet1!C2),1)-1), "")
It truncates until the first found of {".","-","_"}. If you want to truncate till the last found, change 15 into 14.
For your additional requirements:
=IF(ISNA(C2), D2,
IFERROR(LEFT(Sheet1!C2,AGGREGATE(15,6,SEARCH({".","-","_"},Sheet1!C2),1)-1),C2))

Excel search for a string and how many times a charactor is in the cell

I have a list in excel that contain location but some cell have multiple locations separated by " _ " character for Example "_ Location1 _ Location 2" When there are only 1 location I can use Sumif to search for string and add the numbers next to the cell as shown here
My problem is not searching for a string but searching for a character in a list and finding how many there are in the cell it find I was going to add the formula in a different cell then the ones shown above
example formula NOT REAL
=sum(Sumif($A$4:$A$250,"* ~ Location1*",$C$4:$C$250)/Search($A$4:$A$250," ~ "))
I know search does work like this but as an example code this is what I imagine
to find the sum of each location use this array formula:
=SUMPRODUCT((ISNUMBER(SEARCH(D4,$A$4:$A$9)))*($C$4:$C$9/(IF(ISNUMBER(FIND("_",$A$4:$A$9)),LEN($A$4:$A$9)-LEN(SUBSTITUTE($A$4:$A$9,"_","")),1))))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter. If done correctly then Excel will put {} around the formula.
Enter the formula in E4, Hit Ctrl-Shift-Enter, then copy/fill down.
Then to get the total for all simply sum the rows above.
To do it with regular formulas:
You will need a helper column with the following formula:
=C4/(IF(ISNUMBER(FIND("_",A4)),LEN(A4)-LEN(SUBSTITUTE(A4,"_","")),1))
I put mine in Column G.
Then we can use a simple SUMIF():
=SUMIF(A:A,"*" & D4 & "*",G:G)

How to enter information in one cell based on text in another cell

I would like to enter information in a cell based on the text contained in a different cell. Specifically, if a cell in column A contains text that includes "insurance," "retirement," or "401K," then I want to place an "x" in its respective cell in Column B. If not, then cell B1 should be empty. The text needs to be contained within the cell, but does not need to be the exact text. E.g., an "x" would still be placed in the column next to "life insurance" or "insurance," "whole life insurance," etc.
E.g.,
Column A Column B
Life Insurance x
Securities
Retirement x
I tried to use the following formula, but am getting an error message when I do so:
IF(OR(ISNUMBER(SEARCH("insurance",A1,"retirement",A1, "401K",A1)),"x", "")
Any thoughts?
This formula should help:
=IF(OR(ISNUMBER(FIND("Insurance",A1)),ISNUMBER(FIND("Retirement",A1)),ISNUMBER(FIND("401K",A1))),"x","")
EDIT:
I came up with an array formula that I like a little better. Hope this helps:
=IF(COUNT(MATCH({"*Insurance*","*Retirement*","*401K*"},A1,0))>0,"x","")
This will require pressing CTRL + SHIFT + ENTER instead of just ENTER after putting it in the cell because it's an array formula.

Resources