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.
Related
I have a bank export of Credit card vendors. As these vary, I use unique strings contained in each to identify them. For example here is a lookup table excerpt.
First Lookup
I then apply a formula =INDEX(First_level,MATCH(TRUE,ISNUMBER(SEARCH(Keywords,C3374)),0)) to produce this:
First calc
I found this formula here https://exceljet.net/formula/get-first-match-cell-contains
Then I reapply the formula to the result ie the First_Level using this formula =INDEX(Second_Level,MATCH(TRUE,ISNUMBER(SEARCH(Frst_Lev_Check,H44)),0)) with this Lookup.
Second Lookup
Most of the time it works, but for this I get the following
Second calc, where the first level classification is correct, but the second level one is completely wrong.
When I've gone into the depths of the formula, the issue is that the Search function is returning the wrong value.
This appears to be a known issue: https://answers.microsoft.com/en-us/msoffice/forum/all/how-to-use-named-range-in-search-function/14c8c989-bed0-48f9-bce0-c0894571b557
Ideas welcome on workarounds/how to solve the problem.
Cheers Jon
Would you consider:
=MATCH("Apple",List)
and
=MATCH("Pear",List)
to return 1 and 2 respectively.
A couple of things in regards to your question:
The correct syntax for search is =SEARCH(find_text,within_text), so the correct formula would be =SEARCH("Pear",List).
The reason why you are getting the #Value is, because you are applying search to a range, but the function is only intended for cells.
The best ways to see if a value exists in a range are the countif and match function:
The countif function shows you how many times the a value is in a range:
The match function shows you in which row the the first value is:
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.
I have a worksheet looking at football results. I have inserted a formula to discover the longest sequence of blank cells which indicates to me how many games between either wins/draws/defeats. Taking wins as an example which I have in Column H, this formula (The cells in Column H contain either a 1 or are blank)
{=MAX(FREQUENCY(IF(H1:H5077="", ROW(H1:H5077)), IF(H1:H5077=1, ROW(H1:H5077))))}
has told me that the longest sequence without a win for the selected team was 19 matches. That formula and result on my workbook is in cell H5094
What I want to do is discover where amongst 5000+ matches that sequence is?
I've tried this formula which I've used before in an adjacent column and copied down
=IF(COUNTIF(OFFSET(H2,0,0,$H$5094,1),1)=$H$5094,"here","")
however it hasn't worked. I think the mistake is within the formula, possibly the 0 and 1 but I don't know how to put it right, I've tried several variations.
Any help much appreciated.
The method looks fine to me, but the easiest way would be to use COUNTBLANK instead of COUNTIF, so the formula would be:-
=IF(COUNTBLANK(OFFSET(H2,0,0,$H$5094,1))=$H$5094,"here","")
or alternatively
=IF(COUNTIF(OFFSET(H2,0,0,$H$5094,1),"")=$H$5094,"here","")
I noticed that you could get some extra 'heres' if the longest sequence came at the end of the range, but you could fix it by putting a '1' in H5078.
I am trying to use COUNTIF in Excel to find how many items in a range match the contents of a separate cell. The idea is, the range contains everyone's answers to a given question (a one-word, non-numeric answer); the comparison column contains the correct answer. I want a count of how many people got the answer correct.
I tried: =COUNTIF(C16:BT16,"=BU16")
But it appears COUNTIF won't let me reference a cell with the criteria in it -- it requires the match criteria directly in the formula, such as =COUNTIF(C16:BT16,"DEN"). I can do that, of course, but I'd have to edit dozens of formulas every time I evaluate answers, and it would be much less timeconsuming if I could just enter the answers in column BU.
I also tried COUNTIFS; it allows multiple criteria, but also doesn't allow referencing the criteria to a different cell. Searched several different Excel websites too, any suggestions? Many thanks!
Try removing the quotes and equal sign from "=BU18" - that will indicate that you are passing the value at that cell, which I believe is what you're looking for.
=COUNTIF(C16:BT16,BU18)
Assuming BU18 contains DEN. Your first example ("=BU18") is saying "count if any of these cells have a value of "=BU18", which won't match anything (unless they answered some weird questions :) ).
Try this:
=COUNTIF(C16:BT16;BU18)
Please note that you may need to use ";" instead of "," depending on your region.
If you are using Excel 2010, you are even luckier with COUNTIFS
By all means you may use the search range and matching range within countif
e.g. =COUNTIF(SEARCH RANGE, CRITERIA RANGE)
Once again I'm struggling to find my answer on Google, but I'm sure it must exist. Sorry if I come across as a novice: I am when it comes to Excel it seems!
What I'd like to be able to do is tell it to search a range, then find cells within that range that contain text that is in my search function. I don't need any kind of result from it other than either TRUE or >1 (if it matches, obviously).
In this instance I'm searching a RANGE that is comprised of years, one year in each cell, and trying to find cells in that range that contain a year from a list of years that are all in one cell.
Basically I'm wanting to use a function similar to the Search function I think.
=SEARCH(text to find, find within text)
However, I'd like it to do the opposite and find cells that contain some of the text within the source cell:
=SEARCH(find within text, text to find)
Or, more specifically
=SEARCH("2001,2002,2003,2004,2005", "2003")
Is this possible without the use of a Macro? I'd prefer to avoid it if at all possible. All cells in question are formatted as Text.
I have been experimenting with COUNTIF, but again it works in the reverse of what I need.
Sorry if this question is unclear.
Hope someone can help, thanks in advance.
Joe
I'm sure there is a better way, but if I'm understanding correctly, you could try SUM in combination with an array formula (enter with Ctrl+Shift+Enter):
=IF(SUM(IFERROR(FIND(A1:E1,G1),0))>0, "FOUND", "NOT FOUND")
Here, A1:E1 contained the individual years and G1 contained the single cell of years. This runs FIND on each cell in the range, returning a position if it finds a match in the target cell and returning 0 if not (IFERROR is a 2007 function - if you don't have Excel 2007, we can rewrite). You then sum the results of the FIND function and if it is greater than 0, it means you found a match somewhere.