Excel - Checking if cells in range match and then replace cell - excel

I need to check if cell A5(Song Name), B5(Album), C5(Artist) is the same text as any text in Worksheet 2 from A5:A104, B5:B104, C5:C105, respectively.
And if it does, I want the cell I am writing this formula in to change to the same value at E5:E104 from Worksheet 2.
This is what I made, which does not work:
=IF(AND(A5='Worksheet 2'!A5:A104,B5='Worksheet 2'!B5:B104,C5='Worksheet 2'!C5:C104),'Worksheet 2'!E5,"")
What am I doing wrong?

You need to use an array formula to do this. What you were trying to do was nearly right, but it won't work as you expect unless you enter it as an array formula by pressing Ctrl+Shift+Enter. Try this, entered as an array formula:
=IFERROR(INDEX('Worksheet 2'!$E$1:$E$104,MIN(IF(A5='Worksheet 2'!$A$5:$A$104,IF(B5='Worksheet 2'!$B$5:$B$104,IF(C5='Worksheet 2'!$C$5:$C$104,ROW('Worksheet 2'!$E$5:$E$104),2000000),2000000),2000000))),"No match found.")
The logic gets complicated by the fact that you have to use a function that can return a single value from an array (MIN() in this formula).

=IF(ISERROR(MATCH(A5&B5&C5,'Worksheet 2'!A5:A104&'Worksheet 2'!B5:B104&'Worksheet 2'!C5:C104,0)),"",'Worksheet 2'!E5)
Enter as an array function with Ctrl+Shift+Enter

Related

Get element from array constant?

If you have a CSE array constant as follows in cell A1:
{={2,4,6,8}}
How can you get a specific element from the array constant? I tried the following formulas but they all return the first value of the array constant (2).
=INDEX(A1, 0)
=INDEX(A1, 1)
However, it does work if the array is not a reference. The following formula returns the 3rd element (6).
=INDEX({2,4,6,8},3)
Thank you
You could put the array constant in a Name instead of a cell.
Then INDEX will work with it properly with no implicit intersection.
Or you could parse the formula using the FORMULATEXT function, but that sounds tedious.
Try =INDEX(A1#,1). The # tells excel that A1 is a spill formula (more than 1 cell long). The array index starts at 1, not 0 in this case.
As a side note, Index knows you are referring to an index, not a row, when you give it a 1D array. In your example =INDEX(A1#,4) and =INDEX(A1#,1,4) return the Fourth item in your array (8 in this case), but =INDEX(A1#,4,1) will give you the error #REF!. If you define your array vertically {={2;4;6;8}}, =INDEX(A1#,4) and =INDEX(A1#,4,1) both work.
Edit: It looks like this does not always work in Excel 365 when a an array formula is created using Ctrl+Shift+Enter. I think this is due to the changes in 365. Array formulas have pretty much been replaced with spill formulas. Entering ={2,4,6,8} is mostly equivalent to a pre-365 array formula, but creating an array formula with Ctrl+Shift+Enter confines the output to as many cells as selected. In Dan's case, he selected only one cell and the formula doesn't automatically spill, so the formula is confined only to that cell. Excel seems to treat that cell as if it only contains that array element. If you select 2 cells and enter an array formula then =INDEX(A1#,2) will work but =INDEX(A1#,3) returns #REF!.
Edit2: It is possible with the FORMULATEXT Function as #DickKusleika suggested. Here is a function adapted from ExcelJet that does the job.
=LET(
DesiredIndex, 1,
ArrayFormulaRef, A1,
Formula, FORMULATEXT(ArrayFormulaRef),
FormulaLen, LEN(Formula),
CSVStart, FIND("{",Formula,2),
CSV, MID(LEFT(Formula,FormulaLen-1),CSVStart+1,FormulaLen),
TRIM(MID(SUBSTITUTE(CSV,",",REPT(" ",LEN(CSV))),(DesiredIndex-1)*LEN(CSV)+1,LEN(CSV)))
)

If statements in excel not consistent?

In my excel file, I am trying to determine if a set of numbers is greater than the value of another cell.
I have written out an IF statement that only works sometimes depending on the range of the set of numbers. I have been able to replicate the problem but can't understand what is going wrong. I have included an example of my problem.
"B4" is equal to 2
"'Data Sheet'!A1:A10" is a set of 10 numbers from 1 to 10 inclusive.
My first statement (seen below) is working fine:
=IF(B4>'Data Sheet'!A1:A10,"Pass", "Fail")
which returns Fail, as expected.
However, when I change the statement to:
=IF(B4>'Data Sheet'!A6:A10,"Pass", "Fail")
It returns "#VALUE!".
Why does the range of values in the IF statement make a difference to whether it works or not?
Your formula is an array formula, and it is probably due to serendipity that your first formula is returning what you expect as an answer.
When you enter it into a cell as a non-array formula, which is what you are doing, it will return the value from the column A range that is in the same row as the formula.
Had you entered the first formula in Row 1, it would have returned "Pass" since it would be comparing B4 with A1.
If it is not in a row corresponding to a row in the range, it will return #VALUE.
If you confirm the formula as an array formula, by holding down ctrl + shift while hitting enter, then the formula will return an array of Pass;Fail depending on the relationship of B4 to each of the values in A1:A10. (or A6:A10). The visible value in a single cell will be the result of the first comparison.
So you will need to properly evaluate the array, in order to return whatever it is you want from the formula.
I'm not sure of exactly what you want.
If you want to determine if B4 is greater than any of the numbers in A1:A10, then try (entered normally):
If(B4 > MAX(A1:A10),"Pass","Fail")
If you want something else as a result, you will need to be more specific.

Use result of IF formula in single cell Excel array formula

I have a column J with the below array formula:
=IF(ISNUMBER($H$5:$H$263), $H$5:$H$263, $I$5:$I$263)
And a cell on a summary line that references the contents of that column:
=SUMIF($J$5:$J$267,"<"&(TODAY()+365), $L$5:$L$263)
The above gives me the result I want, but I am wanting to consolidate this down into a single formula.
I have tried the below:
=SUMIF(IF(ISNUMBER($H$5:$H$263), $H$5:$H$263, $I$5:$I$263),"<"&(TODAY()+365), $L$5:$L$263)
But it ends up only summing the contents of the left side of the IF
So the below can get me what I want:
=SUMIF(IF(ISNUMBER($H$5:$H$263), $I$5:$I$263, $H$5:$H$263),"<"&(TODAY()+365), $L$5:$L$263) + SUMIF(IF(ISNUMBER($H$5:$H$263), $H$5:$H$263, $I$5:$I$263),"<"&(TODAY()+365), $L$5:$L$263)
But I'm not sure what I am doing wrong with the first shorter formula.
Use this array formula:
=SUM(IF(IF(ISNUMBER($H$5:$H$263),$H$5:$H$263,$I$5:$I$263)<TODAY()+365,$L$5:$L$263))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.
You can use SUMPRODUCT without the need for CSE:
=SUMPRODUCT(((ISNUMBER($H$5:$H$263)*($H$5:$H$263)+(NOT(ISNUMBER($H$5:$H$263)) * ($I$5:$I$263)))<TODAY()+365)*$L$5:$L$263)
I would also recommend the use of EDATE(TODAY(),12) in place of TODAY()+365 to deal with leap year.

Excel find lower distinct value in list

I'm trying to find in a list the lowest unique value.
I tried to find out a way on google, but nothing seem to work like I want.
What i have :
John;5
Leon;7
Mark;5
Bob;3
Peter;3
Louis:4
Desired result: "4" because it's the lower unique value.
Suppose I add in the original list:
Alex;4
The new result is about to be "7" because it's the new lowest unique value.
my excel sheet :
Assuming your data is setup so that names are in column A and values are in column B so that it looks like this:
In cell D2 (or wherever you want the result), use this array formula (Note that array formulas must be confirmed with CTRLSHIFTENTER and not just ENTER):
=MIN(IF(COUNTIF(B2:B20,B2:B20)=1,B2:B20))
You'll know you've entered it as an array formula correctly because you'll see it surrounded by curly braces {=formula}in the formula bar. Do NOT add the curly braces manually.
You'll also notice that I have extra rows in there than just the used rows. Normally I'd suggest using a dynamic named range, but this works for now. So when you add the new line of Alex; 4, you get this:
And you can see the formula now has the new correct value of 7.
With data in columns A and B, in C1 enter:
=COUNTIF(B:B,B1)
and copy down. Then in another cell enter the array formula:
=MIN(IF(C:C=1,B:B))
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
To avoid speed problems, make the limits on the ranges as small as possible:
=MIN(IF(C1:C6=1,B1:B6))

Excel function to test whether string contains ANY of $THESE CHARACTERS

Given:
$Characters
Is there an excel function to test whether a Cell contains ANY of the Characters in $Characters?
There is an array formula method but it also involves the INDIRECT function to check the length of the string to be the $Characters string to be tested. OFFSET is a volatile formula that will recalculate whenever any value in the workbook changes.
        
The array formula in C2 is,
=AND(MAX(IFERROR(SEARCH(MID($E$2, ROW(INDIRECT("1:"&LEN($E$2))), 1), $A2), 0)))
Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered correctly, they may be filled or copied to another location.
I've used the SEARCH function which is case-insensitive. If you require a case sensitive search, substitute SEARCH for the FIND function.
Here is an array formula that should do that.
When you confirm the formula, hold down ctrl+shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula which you can see in the formula bar.
Characters is either a range containing your list of characters (or substrings) to be tested, or an array constant.
=OR(IFERROR(SEARCH(Characters,A1),FALSE))

Resources