Cell A1 is empty, Cell A2 contains "test".
When creating an array formula in cell B1 like this:
{=MATCH(FALSE,ISBLANK(INDIRECT("a1:a2")),0)}
it produces the correct result "2" since the cell A2 contains a non-blank value.
However when creating an array formula in cell C1 which gets row number using the row(a2) function, it results in "1".
={MATCH(FALSE,ISBLANK(INDIRECT("a1:a"&row(a2))),0)}
How can the second formula be modified to use the row(a2) function and get the same results as the first formula, "2" instead of "1"?
Seems like it should work since row(a2) returns 2 so the address string ends up being "a1:a2", same as in the first formula. The point of this is to make the range it searches be dynamic based on the starting row 1 and ending at row(a2) so that if, for example, five rows are inserted between rows 1 and 2, then the a1:a2 range will automatically adjust to a1:a7.
Note these are "array formulas" and need to be entered using ctrl-shift-enter instead of just enter.
Related
Is IF(ISNUMBER(A1:A100),A1:A100,"") an array formula? If not, what is it?
I copied a list of holidays from a web site and pasted it to Excel. The original data had four columns (date, name of the holiday, weekday, note). After pasting to Excel, everything appeared in column A, like this:
date
name of the holiday
weekday
note
date
name of the holiday
.....
.....
I tried several ways to see if the data could be pasted into columns to no avail. So, I needed to extract the dates to another column. In column B, I entered this formula =IF(ISNUMBER(A1:A100),A1:A100,""). It worked to extract the dates from column A to column B.
I am not sure if it is an array formula as, unlike other array formulae, it doesn't need Ctrl-Shift-Enter. Yet, ISNUMBER usually takes a cell as the argument, not an array, and IF usually doesn't return an array.
IF and ISNUMBER are not array functions, but they can be used in array formulas.
Outside of an array formula, they accept only single input values and return single output values.
In an array formula, they can accept an array of inputs values and will return an array of outputs values.
Without pressing CTRL-SHIFT-ENTER, the formula you've specified is not an array function.
What you're seeing is the behaviour when a function that is expecting a single value is given a range and entered without pressing CTRL-SHIFT-ENTER but the input range overlaps with the row where the formula is placed.
Entering a range when a single value is expected will return the value from the range on the same row in which the formula is entered if it overlaps, otherwise it will return an error.
You are getting output only because you are placing the formula next to the rows being referenced; and it is giving the same result as if you had entered the formula normally and then filled down: i.e. putting =IF(ISNUMBER(A1),A1,"") in cell B1 and filling down.
Note that if you entered =IF(ISNUMBER(A1:A100),A1:A100,"") in cell B2 instead of cell B1 and then filled down, then the values still appear in the same row and not shifted down by a row as you might expect. Again, this is because it looks at the value in the same row just because the range overlaps with the current row.
Compare to putting =IF(ISNUMBER(A1),A1,"") in cell B2 and filling down, where you then get the values shifted down by a row as expected.
If you entered the original formula again in cell B101 (below the input range) and filled down, you get no values at all (even if there is data next to the cell) because the input range no longer overlaps the current cell. In fact, if you used the Evaluate Formula tool from the Formulas tab, you'll see that the range A1:A100 returns a #VALUE error immediately.
This behaviour is confusing and should be avoided at all costs. Only enter ranges when a function expects a range, or when an array formula is being intentionally created using CTRL-SHIFT-ENTER.
If after pasting your data to excel sheet looks like below then you can use following formula.
As shown to above screenshot user below formula to C1 cell then drag down and right as needed.
=INDIRECT("A"&(ROW()-1)*4+COLUMNS($A$1:A$1))
This formula will produce 0 (zero) for empty cells. To hide zero (0) use a IF() condition like below.
=IF(INDIRECT("A"&(ROW()-1)*4+COLUMNS($A$1:A$1))=0,"",INDIRECT("A"&(ROW()-1)*4+COLUMNS($A$1:A$1)))
I have a sumif formula wrapped in a sum formula so I can use an array where if the value in cell G2 equals "All" then I want to add up the values in range B2:B4 for three names in the data, but if the value cell G2 equals one of the three names, ie: Tim, then I just want to add up all the values in range B2:B4 for Tim. The formula works fine if only one name is used, but when I enter "All" into cell G2, only the value for the first name is added up. I'm using the below formula:
=SUM(SUMIF(A2:A4,IF(G2="All",{"Tim","Henry","Mike"},G2),B2:B4))
Thanks in advance for any ideas on how to get this to work.
Just in case these three values are the only occuring values in your list, you could just put this in an IF statement, like so:
=IF(G2="All",SUM(B2:B4),SUMIF(A2:A4,G2,B2:B4))
If you have other names in your lookup column, like so:
Your own formula work just fine using it as array formula. You just had to enter it through Ctrl+Shift+Enter
You could use a formula like:
=IF(G2="All",SUMPRODUCT(SUMIF(A2:A5,{"Tim","Henry","Mike"},B2:B5)),SUMIF(A2:A5,G2,B2:B5))
To prevent you have to enter it as array (it's still technically an array formula!)
No need to hard code the array or for an array formula:
=SUMIF(A:A,IF(G2="All","*",G2),B:B)
I am given an excel table. I want to include an additional column which simply contains an index. The column to the right of this index will have some text in it, or be empty. I want to have an index whenever the cell to its right is NOT empty.
Example:
1 Some Text
2 Some Text
3 Some Text
4 Some Text
I was hoping to achieve this by applying the following formula:
=IF(B7="";"";MAX(A4:A6)+1)
The cells given in the MAX() function are all the cells that come before the current cell. This formula works fine, but unfortunately only whenever there are not more than 3 empty cells in between.
Can I make this formula work for an arbitrary amount of empty cells in between?
with data Like:
In A1 enter:
=IF(B1="";"";1)
In A2 enter:
=IF(B2="";"";1+MAX($A$1:A1))
and copy downwards:
The formula in A1 I've used is:
`=IF(AND(B1<>"";ROW()<>1);MAX(INDIRECT("A1:A" & (ROW(A1)-1)))+1;IF(AND(B1<>"";ROW()=1);1;""))`
And I guet this dragging it down:
How it works?
The trick here is MAX(INDIRECT("A1:A" & (ROW(A1)-1)))+1. With INDIRECT you can reference a specific range. The index are always in column A and starts in row 1, that's why I typed "A1:A". But you want to get max value from A1 to Activecell-1, that's why I added (ROW(A1)-1). This will get the row number of active selection minus 1.
IF(AND(B1<>"";ROW()<>1) This is just to check if adjacent cell is not empty, and row number is different than 1. If true, then do the previous step. If false, then do step 3.
If the first IF returns False, could be because adyacent cell is empty, or because row number is 1. So we need to check that with IF(AND(B1<>"";ROW()=1). If true, means B1 is not empty and row number is 1, so index must be forced to be 1. You cannot calculate the max value of a range previous to A1 or it will raise an error. IF this second IF returns False, means adyacent cell is empty, so we do nothing.
In my excel template, I need to have a formula to multiply two numbers with 2 or 3 conditions, and then sum the found numbers in an area.
For example;
First range is; AI22:AI1100
Second range is; AB22:AB1100
Third range is; N22:N1100
Fourt range is; K22:K1100
For first formula, i need to check the second range, found the cells that contain the same value as A2, then get the row number, find the value of the first range/that row cell, then divide it to its fourth range, and go on like this till AB1100 and sum all of that found numbers.
For second formula, i need to check the second range, found the cells that contain the same value as A2, then get the row number, check the third range if its the same value as A3, if it is then find the value of the first range/that row cell, then divide it to its fourth range, and go on like this till AB1100 and sum all of that found numbers.
I tried those with sumproduct, but it only sums both ranges and divides them in the end.
I can write this in Vba, but I need to store the values in the worksheets, so it will be better if I can do this in a formula.
I am open to suggestions.
You want SUM() as an Array formula
=SUM(IFERROR((AB22:AB1100 = A2)*(AI22:AI1100)/(K22:K1100),0))
And:
=SUM(IFERROR((AB22:AB1100 = A2)*(N22:N1100 = A3)*(AI22:AI1100)/(K22:K1100),0))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when Exiting Edit mode.
I have an Excel formula like this:
=SUM(SUMIF(A2:A11;{"1010";"1020"};B2:B11))
Now I need to make the formula more dynamic. Instead of changing the formula itself, I should be able to change some cell (linked in the formula). This change will be reflected in the formula.
Ex:
=SUM(SUMIF(A2:A11;D2;B2:B11))
Cell D2 should return something similar to {"1010";"1020"} in the first formula.
I tried this and it works only if in the column D I have one value (ex: 1020), but if there are two values (ex: 1010;1020) it returns 0.
This is how my table looks like:
As you can see, it shows 0 for the cell where D2 has two values; but it works when there is only one value. All the rows in column D will be like cell D2, with 2 or more values, this is why it has to be dynamic using a list in the formula.
How can this be achieved in Excel? How can I make a list from the cell?
Using multiple cells would be easier! If the formula cell is one to the right of the criteria cell, you can define a named formula (Using Name Manager) called, say, GetList, which refers to this formula:
=EVALUATE("{"&INDIRECT("RC[-1]";0)&"}")
Then your formula becomes:
=SUMPRODUCT(SUMIF(A2:A11;GetList;B2:B11))