Formula Result in Function Argument Window Different Than in Cell - excel

I have the following array formula:
=MAX(COUNTIF(Sheet2!A$2:Sheet2!A$6,Sheet2!A2:Sheet2!A6))
Which is supposed to give me the count of duplicate entries in a small text column in a worksheet. I've put one duplicate entry to test the formula, and the result I should get is 2. Instead, once I ctrl+enter, the cell shows 0. However, when I click the formula button next to the cell content field, it shows Formula result = 2.
Calculation Options are set to Automatic (this is Excel 2010), and I have no idea why this is happening. Any ideas? Thanks.

Seems it was a keyboard problem with the shift or ctrl buttons stuck (: I clicked on the formula inside the formula argument window, then clicked ctrl+shift+enter and it added the curly brackets for the array formula and the result is now correct and updates correctly when the source data changes.

Related

Mode of an horizontal text array in Excel

I have a table where I would like to know the most common value of every row, all the data is text.
expected result is column D in picture
Example in picture.
I have tried this formula but it doesnt work, i only get #Value error
=INDEX(P2:R2,TRANSPOSE(MODE.MULT(IF(ISTEXT(P2:R2),MATCH(P2:R2,P2:R2,0)))))
You can use following array formula:
=INDEX(A2:C2,MATCH(MAX(COUNTIF(A2:C2,A2:C2)),COUNTIF(A2:C2,A2:C2),0))
Array formula after editing is confirmed by pressing ctrl + shift + enter
MODE works on numeric data, so you can, for your example, use:
=CHAR(MODE(CODE(A2:C2)))

Excel - Highlight cell which is closer and smaller to a specific value

I would like to highlight a cell which is the closest the a specific value but still lower (below) or equal according to a formula.
For instance, if I have 14 in B4, I would like the cell 13 (or 14) highlighted but not 15 in the range.
The value I need to look for would be in B4 and the range that I must apply the highlight formula to would be L1:L371.
So far, the best result I was able to achieve was with (from what I was able to find using Google or Stackoverflow already existing content):
=SMALL($L1:$L317,COUNTIF($L1:$L371,"<="&$B$4))
Although, not only it selects the value I am looking for, it also selects all the values below.
May someone provide me some help so I can achieve the expected result please?
Thank you for your time and help, it is greatly appreciated.
Based on your description, it seems like you need to find the maximum value of a range (L1:L137) that is less than or equal to an input variable (B4) and highlight that value in the search range. Depending on what version of Excel you have, here's what you need to do:
For Excel 2019 or Excel 365
You can use the MAXIFS function. You would actually put that function in a conditional formatting rule, but more on that in just a second. As a test, put the following code in cell B5:
=MAXIFS($L$1:$L$137,$L$1:$L$137,"<="&$B$4)
The first argument is your "MAX_RANGE", or the range that contains the values you want to find the max of. It is also our "CRITERIA_RANGE", the second argument. The third argument is the criteria itself, which is that the search range must be less than or equal to the value in cell B4. Essentially, we are going through the list and creating a subset of numbers that are less than or equal to our search value, and discarding the rest. I assume you are aware of relative vs. absolute referencing, since you used the "$" anchor in your referenced code. If not, here's a description of the difference.
Now, the result of that formula should be the highest number in the list less than or equal to the search value, but that doesn't highlight it for us in our list. To do this we need conditional formatting. To do this, highlight your data range (L1:L137) and go to the conditional formatting drop down on the home tab of the menu ribbon. Choose "New Rule". On the dialog that pops up, choose, "Use a formula to determine which cells to format". In the formula input box, enter:
=L1=MAXIFS($L$1:$L$137,$L$1:$L$137,"<="&$B$4)
This will compare whether the value in the cell being evaluated (L1, for instance) is equal to the result of that formula we talked about above. Since L1 is only relatively referenced, this formula will work for every cell in the data range.
Now, before you hit "OK" on the dialog, select the Format button. This will allow you to adjust your highlighting and formatting as you desire. Click "OK" on the formatting dialog, then "OK" on the Conditional Formatting Rule dialog. This should now highlight any data cell that is equal specifically to the result of our formula, and not everything that's less than our value.
For Earlier Versions of Excel
The concept is the same in earlier versions of Excel, but unfortunately, the MAXIFS function is not present in these versions. Instead, we must use an array formula. Array formulas are a whole other can of worms, but ExcelJet is an excellent resource. In fact, they talk about this very issue, here.
Unfortunately, we can't put the array formula in the conditional formatting formula like we did above, so we'll need to put this formula on a cell in the worksheet, then the conditional formula should reference that new cell. So in cell B5, if you put:
=MAX(IF(L1:L137=B4,L1:L137)
And then, instead of pressing Enter, you must press Ctl + Shift + Enter
This keyboard combination will tell Excel that you are trying to enter an array formula. If you don't press these keys, then the formula will error. Once you have entered the array formula, if you put your cursor in cell B5, you will see the formula bar at the top has added curly braces ({ , }) around the formula to look like
{=MAX(IF(L1:L137=B4,L1:L137)}
This leads to the same result as above, but is just achieved slightly differently. Now, following the same process described above for conditional formatting, you will simply set the formula to:
=L1=$B$5
And that should be it! Hope this helps!

How to declare a two-dimensional array by one cell formula?

In Excel it is pretty simple, for example
={1,2,3,4;5,6,7,8} gives us 2 rows in 4 columns.
But when I try similar in Google Spreadsheet, it fails.
EDIT: See comments below where the language version issue was revealed.
Nearly the same syntax, but different entry methods:
Excel
Hi-light a block of cells and array enter:
={1,2,3,4,5,6,7,8}
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.
Google Sheets
Select a single cell and enter:
={1,2,3,4,5,6,7,8}
and the extension to the other cells occurs automatically:
Same is true for 2-D arrays:
If you are using Google Sheets, remember to leave enough empty cells to the right and below to hold the result.

Excel 2010 CountIf function only works with debug

I have the following excel function:
=SUM(COUNTIF($B22:$BA22,$BY$4:$BY$49))
The first range B22 - BA22 is filled with formulas that read data from other spreadsheets.
The values displayed in those cells are like "1234Pass", "3456Fail".
The values in the second range, BY4 - BY49, contain all of the possible Fail values. Those are typed in manually. All Cells are formatted as general.
The SUM formula above always displays 0 in the cell. However if I click in the formula bar and press F9, the correct value is displayed.
What am I doing wrong?
Enter the formula as an array formula -- hold down ctrl+shift while you hit enter. Excel will put braces {...} around the formula if you do it correctly

Excel - Sum contents between headers if a string is found

I'm trying to do the following: if it finds a letter "A" in the 3rd column, sum all the values of the 2nd column (that are in the same line as the "A"), but, between the headers is a single range.
I've tried using arrays and other type of functions, but I'm not getting anywhere..
The tricky part is that the sum must restart when it finds a new header.
There are no gaps between headers.
Thanks everyone!
PS. Actually, there aren't any 'blocks' without an "A", like the one you can see below the 2nd header. I've already filtered and deleted those.
You could try entering this in cell D2 and fill down:
=IF(LEN(C3)<>1,SUMIF($C$2:C2,"A",$B$2:B2)-SUM($D$1:D1),"")
... but if you have many rows it would be preferable to fill simple SUMIF formulas using code. One way to do this is to press Alt+F11 to access the VB code window, then enter in the immediate window this line and press enter:
[E1:E13]=[IF(LEN(OFFSET(C1:C13,1,0))<>1,"=SUMIF(C"&LOOKUP(ROW(C1:C13),ROW(C1:C13)/(C1:C13="H3"))+1&":C"&ROW(C1:C13)&",""A"",B"&LOOKUP(ROW(C1:C13),ROW(C1:C13)/(C1:C13="H3"))+1&":B"&ROW(C1:C13)&")","")]
This enters these three formulas in the cells shown and leaves the remaining cells blank.
E4 =SUMIF(C2:C4,"A",B2:B4)
E9 =SUMIF(C6:C9,"A",B6:B9)
E13 =SUMIF(C11:C13,"A",B11:B13)

Resources