When I'm trying to use the and(exact()) function on Excel to see if the values match across a range, if my range is across the same row, I'm getting a formula error whereas if my range is across the same column, I'm getting a TRUE/FALSE output, but it's wrong.
Does anyone know why I'm getting the wrong output?
Short Answer
It is because this is an array formula. You must press Ctrl+Shift+Enter on the keyboard after typing this formula rather than just pressing Enter.
Long Answer
Since this is a pretty simple formula, you can actually use alternatives that are not array formulas.
For example instead of:
= AND(EXACT(A4:A6,A4))
You can do this:
= SUMPRODUCT((A4:A6<>A4)+0)=0
And instead of:
= AND(EXACT(A2:D2,A2))
You can do this:
= SUMPRODUCT((A2:D2<>A2)+0)=0
The formulas have the same final result, but those with SUMPRODUCT are not array formulas. (This is in this specific case only. It is possible to have an array formula that contains SUMPRODUCT.)
Related
In Google Sheets, it's possible to create an array with formulas with in it. For example, ={SUM(1,2);SUM(3,4)} evaluates to a column with the numbers 3 and 7.
When I try the same thing in Excel, I get a formula syntax error. Is a similar thing possible? I've also tried putting names defined with LET in an array, but that throws the same error.
Thanks!
You can use CHOOSE function to combine formulas in array:
=CHOOSE({1;2},SUM(1,2),SUM(3,4))
formula works for O365, for earlier versions select desired count of cells and enter formula in first cell as array formula (with CSE).
I am trying to write a formula in Excel that will find the closest match in one column and return that value, so that it can be used in a SUMIFS formula. I have done some investigating and found that everyone points at this specific formula:
{=INDEX(data,MATCH(MIN(ABS(data-value)),ABS(data-value),0))}
The issue I am having though is I am trying to convert this to use data from a Table and have this so far:
{=INDEX(_CCD01[[#All],[Date]],MATCH(MIN(ABS(_CCD01[[#All],[Date]]-TODAY())),ABS(_CCD01[[#All],[Date]]-TODAY()),0))}
But Excel returns a #VALUE! error.
What the formula needs to do, is find the closest date in column _CCD01[[#All],[Date]] using TODAY() as the search criteria.
The file with the table and formula can be found here:
Dropbox Read Only
Any help or thoughts will be appreciated.
Dave
This is an array formula.
=INDEX(_CCD01[Date],MATCH(MIN(ABS(_CCD01[Date]-TODAY())),ABS(_CCD01[Date]-TODAY()),0))
To enter/confirm an array formula, hold down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula seen in the formula bar.
The syntax you were using _CCD01[[#All],[Date]] will also return the header row of the column. There's no need for this, and it is the cause of your #VALUE! error.
The ABS function will return a #VALUE error (as the first element) in the array it returns when applied against the column since the first entry is text.
And then MIN arguments that are error values or text that cannot be translated into numbers cause errors.
Similar questions to this have been asked but not exactly like this. There is one that is very close, but that solution is not working for me.
I have a function which returns comma separated values into a cell. I would like to pass the elements in that cell as criteria to a SUMIFS function using an approach like this one.
My attempt is pictured below:
I believe that this is somehow tied to the way that the function is understanding what is in cell G8. It looks like it is adding some extra quotes. If I highlight G8 in the formula bar and press F9, I get:
There are extra quotes on each side of each criteria.
I am open to a custom VBA function solution, but I would prefer something which can be built as a worksheet function. The criteria are returned from a custom VBA function that pulls elements out of a list box and does some regex work to remove extra commas. The number of elements that can be selected is variable so I would like to avoid having to split the criteria into more than one cell. Thanks.
Seems that the raw comma-separated criteria is in G6, All you need is to split this criteria into an array and feed it to SUMIFS. Splitting is available in VBA, but not exposed to Excel. All we need is to write a little UDF that does the splitting of the CSV and use it in our formula:
Function splitCSV(str As String)
splitCSV = Split(str, ",")
End Function
Now the formula in F10 would be:
=SUM(SUMIFS(C3:C10, B3:B10, "blue", A3:A10, splitCSV(G6)))
EDIT
The above is an array formula (Ctrl+Shift+Enter). To have it a normal formula we can use SUMPRODUCT instead of SUM. This leads to more flexibility (normal formula vs array formula) as well as some "expected" performance improvement.
=SUMPRODUCT(SUMIFS(C3:C10, B3:B10, "blue", A3:A10, splitCSV(G6)))
I have two sheets with the same line of cells, for example, A1:A5.
I need to check if the value of every cell in Sheet1!A1:A5 is equal to Sheet2!A1:A5 but the hitch is the values will be letters, and all values are different. Simply typing the formula got me a #VALUE! error.
I know I can just write the formula:
=IF(Sheet1!A1=Sheet2!A1;1;0)
and then simply retype it in a number of cells with different values, but I'm looking for a way to shorten the formula.
Any suggestions?
To shorten the formula use array function. With that you will be able to check the whole range at once.
=IF(AND(Sheet1!A1:A5=Sheet2!A1:A5);1;0)
After typing the formula press Ctrl+Shift+Enter instead of just Enter key to confirm array formula.
This one is a little shorter
=(Sheet1!$A1=Sheet2!$A1)
You could use
AND(EXACT(Sheet1!A1, Sheet2!A1), EXACT(Sheet1!A2, Sheet2!A2), EXACT(Sheet1!A3, Sheet2!A3), EXACT(Sheet1!A4, Sheet2!A4), EXACT(Sheet1!A5, Sheet2!A5))
But in the following way:
Have a separate column with the code (let's say, column G)
EXACT(Sheet1!$A1, Sheet2!$A2)
To the column next to that, have a single cell with the code
AND(G1:G5)
Use the AND() function:
IF(AND(Sheet1!A1=Sheet2!A1,Sheet1!A2=Sheet2!A2,Sheet1!A3=Sheet2!A3,Sheet1!A4=Sheet2!A4,Sheet1!A5=Sheet2!A5),1,0).
EDIT
Not realy sure about your aim,
If you want it short because it is too difficult to write the above function, then try the method below:
=IF(CONCATENATE(Sheet2!A1,Sheet2!B1,Sheet2!C1,Sheet2!D1,Sheet2!E1)=CONCATENATE(Sheet1!A1,Sheet1!B1,Sheet1!C1,Sheet1!D1,Sheet1!E1),1,0)
But this is not without catch, it could return false positive. So use it with care. To overcome the false positive, I could only make the formula longer (but still relatively easy to write out).
=IF(CONCATENATE(Sheet2!A1,"|",Sheet2!B1,"|",Sheet2!C1,"|",Sheet2!D1,"|",Sheet2!E1)=CONCATENATE(Sheet1!A1,"|",Sheet1!B1,"|",Sheet1!C1,"|",Sheet1!D1,"|",Sheet1!E1),1,0)
This links to question 12299700 - I want to understand why SEARCH returns #Value when used alone but works when embedded into LOOKUP, and how I can make it work alone:
In Cell A1 I have a string of text: "This is some sample text"
In Cells D1:D4 I have words: "text, sample1, sample2, string" (all in separate cells)
I want to see if my string contains any of the words in my range - I don't need the matching word/s returned.
Using the Search function in any empty cell in Row 1 =SEARCH($D$1:$D$4,A1), returns 22. Good!
Using this in any other row returns #VALUE. Why?
If I keep my formula in Row 1, but move my range of words down to D2:D5, I get #Value. Why?
How can I make SEARCH work for my cell and ranges, in any cell?
(From the answer to question 12299700 I know I can use this formula to return the matched text, in any cell of the spreadsheet: =LOOKUP(2^15,SEARCH($D$1:$D$4,A1),$D$1:$D$4) - this includes a term that gives #VALUE on its own ... intriguing).
First question asked on Stackoverflow - feedback appreciated.
The function SEARCH returns #VALUE if the searched string was not found within the text. The function SEARCH expect only one searched string. It is not a array function itself. So if it gets a range as searched string, it uses only one of these range values as searched string. Which one it is, depends on the position of the formula.
Within LOOKUP the case is completely different. LOOKUP is an array formula itself. It gets the SEARCH($D$1:$D$4,$A$1) as { SEARCH($D$1,$A$1), SEARCH($D$2,$A$1), SEARCH($D$3,$A$1), SEARCH($D$4,$A$1) } which results in a array like { #VALUE, 21, #VALUE, 21 } depending of if SEARCH finds the string or not. That LOOKUP even works with such an array is strange. Normally it needs a sorted array. But it works and gets the last value which is lower or equal than the searched value.
If you need to use SEARCH like an array formula outside a native array formula, then you have to create this array context by entering the formula with [CTRL]+[SHIFT]+[ENTER] instead of only [ENTER]. The formula gets then curly braces around it.
In my example I have created such a formula in Cell E10.
If you are interested in how formulas work, you should often click fx and look how the single parameters comes through. And you should often use Evaluate Formula on the Formulas tab, in the Formula Auditing group.
What happens is that SEARCH is being used in an array form and is outputting in a linear form (non-array).
So, what happens in row 1 is that you're actually doing:
=SEARCH($D$1,A1)
Because evaluating a linear formula with an array tends to take the value from the array in the same row/column depending on the situation. So that means the above is looking for text in A1 which can be found.
On the second row, you will get:
=SEARCH($D$2,A1)
Which means it is searching for sample1 from A1 and since it cannot be found, you get #VALUE!.
To evaluate an array formula as an array, you will have to use Ctrl+Shift+Enter instead of pushing Enter after typing in the formula. Now the problem is that the formula above will return the same thing if you use only 1 cell...
If you want to see if your string contains any of the words in your range (and it's not important to know what word was found), then you will have to use another function along with SEARCH, for example, SUM and ISNUMBER and evaluating it as an array formula:
=SUM(ISNUMBER(SEARCH($D$1:$D$4,A1)))
And if you get a number above 0, you know there's at least 1 word in the text. Maybe to make the output more explicit:
=IF(SUM(ISNUMBER(SEARCH($D$1:$D$4,A1)))>0, "Word(s) found!", "No words found...")
If you want to know what word was found, you will have to use it as a normal formula and drag it down:
The reason why it works in VLOOKUP is that this function actually expects an array as the second parameter and since SEARCH is returning an array, well, that works out just well.
Also, you can view how functions work by clicking on the cell with the function, then do to 'Formulas' in the menu bar and clicking on 'Evaluate formula':
From there you can see if something is being evaluated as a linear or array formula and see how cell references are being substituted with the actual values.