Excel string extraction - excel

My question is, I want to find a specific characters "V-", "C-", or "To", from the value in the cell B2,
The logic is: if either of these characters are found in the cell B2, the excel should take value from D2, and put into new column say E
Here is my if formula:
=IF(MID(B2,FIND("V-",B2),2)="V-",D2,
IF(MID(B2,FIND("C-",B2),2)="C-",D2,
IF(MID(B2,FIND("To",B2),2)="To",D2," ")))
This formula is working for only first occurrence "V-" in this case , the rest of the values it displays "#VALUE!". Can I get any help please.

And return a blank otherwise?
=IF(COUNT(FIND({"V-";"C-";"To"},B2)),D2,"")

Just to spell out what's happening, if it Find fails to find "V-", it immediately returns a #VALUE! error and the formula doesn't proceed any further.
You could fix it like this while preserving your logic
=IF(ISNUMBER(FIND("V-",B2)),D2,
IF(ISNUMBER(FIND("C-",B2)),D2,
IF(ISNUMBER(FIND("To",B2)),D2," ")))
but as you can see from the other answers there are much shorter ways of doing it.

Try this way:
`=IFERROR(FIND("V-",B2),IFERROR(FIND("C-",B2),IFERROR(FIND("To-",B2)," ")))`
returning a positive number when found or " " when no match.
(I could not test it because I use a localised version of Excel but the logic is fine)

Related

Extract information before several special characters in excel

I have a problem with an excel file.
I am trying to extract information from a column. This information appears randomly, before a ".", "-" or ":". So an example would be:
CELL
EXPECTED RESULT
hi.this is:
hi
maybe I- this works
maybe I
Who is: what. like-
Who is
I am using the formula:
=MID(A1,1,FIND("-",A1,1)-1)
Using this one, I get the information I need, but I am not able to add the other characters (".", ":",...) to the formula. Also I have the problem that in a same cell, I can have several of this characters, and I only want the information before the FIRST character (of all posible kinds) that appears in the cell.
I dont know if somebody can help me here.
Thank you very much in advance!
You can try:
Formula in B1:
=TEXTBEFORE(A1:A3,{".","-",":"})
If you don't yet have acces to TEXTBEFORE() then try:
=LEFT(A1,MIN(FIND({".","-",":"},A1&".-:"))-1)
I suppose this is an array-entered formula in versions prior to ms365.

Double nested IF statement formula in Excel

Good morning,
I would like to set a multiple if statement in Excel.
In row 8 you can see the following formula, which gives an answer in column Q. The answer based on this nested formula is Yes or No.
In row 13 all the cells are empty. Because the nested formula has been dragged down it still shows "No".
I was trying to write some double nested IF statement for this, which could cover the situation when the cells are empty and the Q column can come empty as well as a result.
=IF(OR(M9=" ",OR(N9=" ",OR(O9=" ",OR(P9=" "(IF(OR(M9="No", OR(N9="No", OR(O9="No",OR(P9="No")))))),"Yes","No")," ")
Unfortunately, the formula is not working.
Is it a possibility to add up an additional condition for the nested IF statement in Excel?
Something like:
=IF(COUNTA(M2:P2),<YourFormula>,"")
Where <YourFormula> is a placeholder for whatever formula you are interested in when any value in M2:P2 has a value.
As #JvdV has noted in comment above, your latest formula in comment above is still checking for a space, not a null (empty) cell.
Writing " " will look for a cell that contains a space (someone has hit spacebar). Writing "" will check to see if a cell contains nothing, in other words check to see it is empty.
I also noticed the error in your re-write: You wrapped the logical test within the parenthesis for the COUNTA formula. This is your formula corrected:
=IF(COUNTA(M9:P9)=0,(OR(M9="No",OR(N9="No",OR(O9="No",OR(P9="No"))))),"")
However, each OR statement gives a TRUE or FALSE result and can handle multiple arguments, as indicated by #SolarMike so I think you could probably re-write your formula to as follows to get the same result, if I have understood your requirements correctly:
=IF(COUNTA(M9:P9)=0,IF(COUNTIF(M9:P9,"No")>0,"Yes","No"),"")

Excel - Minimum and If statement - date error

I am trying to write a formula that checks the status and name to be ongoing and joe blogs (in this example), and once finding a match, will identify the oldest date of a ticket raised.
My formula currently includes:
=MIN(IF('Sheet2'!AA:AA="ONGOING",IF('Sheet2'!Q:Q="Joe Bloggs",'Sheet2'!B18:B49)))
I also tried:
=IF((AND(sheet2!$AA:$AA="ongoing", 'Sheet2'!$Q:$Q="Joe Bloggs")), MIN('Sheet2'!B18:B49),"No")
In Column B contains dates. Q contains names, AA contains the status.
At the moment when this runs I get the result '00/01/1990'.
I have done some checks to find the error, and appears to be around the targets name, as when the second formula is tried, the output is "no". The name is definitely in the Q column, and I have completed other formulas including countifs which have worked perfectly fine.
I have done a lot of searching to find nested ifs and min statements to have no joy , would be grateful of any advice / tips. It may be a simple error to some.
Try entering this as an array formula:
=MIN(IF(sheet2!AA:AA="ongoing",IF(sheet2!q:q="Joe Bloggs",sheet2!B:B)))
FYI I found the solution here.
You will have to apply a date format to the result.
Your first formula works well on my data (as below). If I close the formula with ENTER only, I get the result '37128' and if I close the formula with CTRL+SHIFT+ENTER I get the expected result, '25/08/2001'.
Edit: As #FocusWiz said in the comments, the only major difference (other than different column names) between my formula and yours is the the last range in your formula (B18:B49) is a different sized range to the other two, which are referring to full columns.
*This could be solved either by using the same row range for all three column references (AA18:AA49, Q18:Q49, B18:B49) or referencing the full column range for all three ranges (AA:AA,Q:Q,B:B).
This is your formula I'm talking about:
=MIN(IF('Sheet2'!AA:AA="ONGOING",IF('Sheet2'!Q:Q="Joe Bloggs",'Sheet2'!B18:B49)))
And this is the formula in my workbook F7:
=MIN(IF(B:B="ONGOING",IF(A:A="Joe Bloggs",C:C)))
As you can see in the formula editor, squiggly brackets '{}' show around the formula when it has been closed as an array formula.
If that doesn't work for you, please post some sample data with datatypes so we can help figure out what is causing the lookup value to miss the data.
While I like the technique offered by Patrick (I have frequently forgotten an "else" portion of a formula and gotten "false" as a value in a cell but never thought of a use for that...thank you!), I think this question highlights an issue we all can have with array formulas. As girlvsdata indicates, your original formula:
=MIN(IF(Sheet2!AA:AA="ONGOING",IF(Sheet2!Q:Q="Joe Bloggs",Sheet2!B:B)))
(modified above to be more generic for column B) will also work when entered as an array formula.
What likely happened is that somehow the formula got edited and was not re-entered as an array formula.
While I do not dislike array formulas, I do try to avoid them because I have fat fingers and will frequently mess them up by accidentally hitting the wrong key as I am modifying other cells.
Here is an alternative without using an array formula:
=INDEX(LARGE((Sheet2!Q:Q&Sheet2!AA:AA="Joe bloggs"&"ongoing")*(Sheet2!B:B),COUNTIFS(Sheet2!Q:Q,"Joe Bloggs",Sheet2!AA:AA,"ongoing")),1)
What it does is basically create a candidate date value for every row that has "joe bloggs" and "ongoing" which is equal to the date in column B for all such rows. All other rows get a zero candidate date value. The LARGE function takes the smallest nonzero date by counting the n valid candidates with the COUNTIFS function and taking the nth largest such candidate.

Excel - IF Formula with a FIND

I have an excel document I have to process regularly, while awaiting my company to build an automated process for this, and the issue we recently found is that the formula I'm using strips can't return a result other than #VALUE! when the FIND formula fails to find the text I need it to.
the formula we currently have is:
=IF(FIND("-",M2,3),RIGHT(M2,2))
The cells this formula checks have states, & provinces in them which look like so "CA-ON" or "US-NV".
The problem is that regions for the UK don't fillout as "UK-XX" it inputs the actual county for example "Essex" or "Merryside"
What I need the formula to do is, if it can't find the hyphen(-) in the cell, then it should just take whatever value is there and write it in the cell the formula is in.
I should also mention that some of the cells are also blank, since this is an optional field. Is there anyway to run this formula where if it doesn't find the "-" it just writes whats there?
What about using mid() to see if the third character is "-"
=IF(MID(A1,3,1)="-",RIGHT(A1,2),A1)
If you really want to use the find() function then:
=IF(ISNUMBER(FIND("-",A1)),RIGHT(A1,2),A1)
The IFERROR Function should help here. And there isn't a reason to use the if statement anymore. The formula below will find the hyphen if it is in the first 3 characters, and find the length of the string minus the location of the hyphen and return that string. The IFERROR will catch the instances where there is no hyphen and return your original cell.
=IFERROR(RIGHT(M2,LEN(M2)-FIND("-",LEFT(M2,3),1)),M2)

Excel Match Multiple Criteria plus Search

This follows on from my 2 previous questions: Excel Match multiple criteria and Excel find cells from range where search value is within the cell. Apologies if I'm over-posting but I figured each question is slightly different and bothering people for follow-up questions doesn't seem fair if I can't mark their answer as correct.
I have this working piece of code which checks 3 columns of data to return a value from range1 if all of the criteria are met:
=INDEX(range1,MATCH(1,(A2=range2)*(B2=range3)*(SEARCH(range4,J2)),0))
However I need the SEARCH option to work if a match is found in range4 OR range5, and thanks to John Bustos and Barry Houdini from this site I know how to use an OR command within a MATCH Function:
=INDEX(range1,MATCH(1,(A2=range2)*(B2=range3)*(((C2 = range4)+(D2 = range5))>0),0))
The code above works for exact matches but the Values of C2 and D2 are lists of numbers contained in single cells, and range4 and range5 are single years in each cell so the SEARCH function has to be used to check whether the single years are present within the list of years. So, judging by the two working pieces of code above I thought this would work:
=INDEX(range1,MATCH(1,(A2=range2)*(B2=range3)*(((SEARCH(range4,J2))+(SEARCH(range5,J2))>0)),0))
However, it does not, and nor does:
=INDEX(range1,MATCH(1,(A2=range2)*(B2=range3)*(((SEARCH(range4,J2))+(SEARCH(range5,J2)))),0))
I am remembering to Press CTRL+SHIFT+ENTER, it just always returns #N/A. I know it should be returning values as the first example works before I try and make it into an OR command.
I hope someone can shed some light on this. Thanks in advance,
Best Wishes,
Joe
The problem you get in changing to SEARCH is that with C2=range4 in previous version of the formula the result of that is either TRUE or FALSE whereas SEARCH(range4,J2) returns a number (position of range 4 value in J2) or a VALUE! error if it isn't in J2
...so if only one SEARCH finds a value and the other doesn't you'll still get the error generated by the one that doesn't and MATCH won't get a match, so the "OR" doesn't work........to fix that you need to add something to get the SEARCH to return TRUE or FALSE - you can do that with ISNUMBER, i.e.
=INDEX(range1,MATCH(1,(A2=range2)*(B2=range3)*(ISNUMBER(SEARCH(range4,J2))+ISNUMBER(SEARCH(range5,J2))>0),0))
Note also that the first formula you quote:
=INDEX(range1,MATCH(1,(A2=range2)*(B2=range3)*(SEARCH(range4,J2)),0))
may not work as intended because SEARCH might return a number other than 1, so you need ISNUMBER there as well, i.e.
=INDEX(range1,MATCH(1,(A2=range2)*(B2=range3)*ISNUMBER(SEARCH(range4,J2)),0))
For array formulas isnt it "Ctrl + Shift + Enter". Try that and see if it does anything.

Resources