multiplying cells and sum then for a range - excel

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.

Related

Excel count non emtpy cells

I have a string in the cell A1 in sheet name Sheet 1.
I now use the MATCH function to find the string of cell A1 in the range A1:Z1 of a different sheet.
That works fine so far. The function returns the column number. (let's say 5, in column E)
My overall goal is to determine how many non-empty cells I have in a certain column. For that, I can use the COUNTA formula which expects a range as parameter. My problem is that I do not know how to convert the number of a column into a valid range without using VBA.
Manually I would do COUNTA(E:E) but I need to create a range for a numbered column like 5.
Thx.
Use INDEX:
=COUNTA(INDEX(Sheet2!A:Z,,MATCH(A1,Sheet2!A1:Z1,0)))

Is this an array formula, IF(ISNUMBER(A1:A100),A1:A100,"")

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)))

Return multiple values from a range

To return a value corresponding to another cell from a range if it matches with a cell, I found Chuff's solution helpful (in
Excel - match data from one range to another and get the value from the cell to the right of the matched data ):
=iferror(vlookup(b31,$f$3:$g$12,2,0),"")
However, if there are more than one cells within the column F which match with b1, the formula returns the value of only one cell from the column G.
Could it be modified so as to attract the value of more than one cell?
Thank you!
To return multiple corresponding Vlookup values you should use this formula: =IFERROR(INDEX($B$2:$B$9,SMALL(IF($E1=$A$2:$A$9,ROW($A$2:$A$9)-ROW($A$2)+1),COLUMN(A1))),"")
Because it it an array formula, please enter it using combination of CTRL+SHIFT+ENTER . For example, if you have you lookup range in A:B column, and lookup values in D column, then please enter formula above to F1 cell, then drag it to the right and to the bottom. You should now see all instances of Vlookup next to the lookup value in D column.
If you have only values which you want to sum in case they correspond to your value in cell B31, then simply use SUMIF formula like this =SUMIF($F$3:$F$10,$B31,$G$3:$G$10) entered in cell C31.

Count last 10 cell values if >1, exclude blank cells

I am trying to figure out how to count the last 10 cell values that are bigger than 1, in a given range, and to exclude blank cells. The formula should handle last 10 non-blank entries dynamically in a column.
I have this array formula from another forum:
=IFERROR(AVERAGE(IF(ROW(A2:A20)>=LARGE(IF(A2:A20<>"",ROW(A2:A20)),MIN(COUNT(A2:A20),10)),IF(A2:A20<>"",A2:A20))),"")
It averages the last 10 cell values, excluding blanks.
I have tried to replace the "average" function with "countif", and I added ">1", but without success,it returned zero.
The problem with your question is that you only need last 10 cells of your range. Assuming your range is A2:A20, you count the last 10 values greater than 1 as follows:
=COUNTIF(OFFSET(A2,ROWS(A2:A20)-10,0,10,1),">1")
Note that you have to type in the first cell of the range (A2) as well as the whole range (A2:A2O) and you have to type number 10 twice, but that's how Excel programming is...
Made some changes in your formula:
=IFERROR(SUM(IF(INT(IF(ROW(A2:A20)>=LARGE(IF(A2:A20<>"",ROW(A2:A20)),MIN(COUNT(A2:A20),10)),IF(A2:A20<>"",A2:A20)))>1,1,0)),"")
This is an array formula so commit it by pressing Ctrl+Shift+Enter.
Instead of COUNTIF function, I am using SUM(IF()). For deatils see this.
Here, INT function converts False to 0 and TRUEto 1.

Count number of blank cells in row between last cell and next non-blank cell

Is it possible (with a formula preferably) to count the number of blank cells in row, where the counting starts at a given column and counts going backward (e.g. right to left) the number of blank cells until a non-blank cell is found? In the example below, the counting begins at Column H and proceeds leftward. Using COUNTA or COUNTIF seem like reasonable tools to use, but I am unsure on how to terminate the counting once a non-blank cell is found.
You can use something like this if the values in your table are all text:
=COUNTBLANK(INDIRECT(CHAR(97+MATCH("zzzz",B2:H2))&ROW()&":H"&ROW()))
MATCH("zzzz",B2:H2) returns the column number in which the last non-blank cell is.
CHAR(97+ column number) returns the letter of that column.
Append it to the row number to give the reference where the COUNTBLANK has to start with &ROW()
&":H"&ROW()) gives the reference of the last cell, which is H plus the row number.
INDIRECT turns the concatenated text into a range that Excel can evaluate.
Try this formula
=COLUMNS(B2:H2)-MATCH("zzzz",B2:H2)
You could use nested if statements
=IF(ISBLANK(H2),IF(ISBLANK(G2),IF(ISBLANK(F2),IF(ISBLANK(E2),IF(ISBLANK(D2),IF(ISBLANK(C2),IF(ISBLANK(B2),IF(ISBLANK(A2),8,7),6),5),4),3),2),1),0)

Resources