Arrayformula count how many cells in a row are less than cells in another row only if both are nonzero/nonblank - if-statement

I found this formula, =arrayformula(sumproduct($C$24:$C$31<B$24:B$31)) but I need it to ignore if one or both cells are 0 or blank.
I've tried and, and countifs, but I can't seem to figure it out.
=arrayformula(sumproduct($C$24:$C$31<B$24:B$31))
I want a number 0-8 for counting how many cells in the particular row are less than the compared row, but (i.e. 0<25) needs to be ignored.

try it like this:
=ARRAYFORMULA(SUM(IF((C2:C < B2:B) * (C2:C<>0), 1, 0)))

Related

How to collect data and headers for non blank cells in a row in Sheets

I cannot find a solution to my problem:
I have a sheet with ~290 rows and ~80 columns. The first row and column are fixed/header.
I would like to collect non-blank values and their header into column B.
I've tried to search for solutions, but I'm not as good at excel, so I cannot wrap my head around most of the advice that I've found.
In Google Sheets you could use an Array formula. I got this:
The formula I've used:
=ArrayFormula(CONCATENATE(IF(--(C2:G2<>"")*COLUMN($C$1:$G$1)<>0;$C$1:$G$1&" "&C2:G2;"")))
This is how it works:
(--(C2:G2<>"") will return an array of 0 and 1 if the cell is blank or not
COLUMN($C$1:$G$1) will return an array of column numbers of each cell
(C2:G2<>"")*COLUMN($C$1:$G$1) we multiply both arrays, so we will get an array of column numbers of non blank cells and 0 of blank cells
<>0;$C$1:$G$1&" "&C2:G2;"") We check if each number in the array obtained in step 3 is 0 or not. If it's 0, it returns a null value, if not, it returns the value of cell
CONCATENATE will concatenate all values from previous array (step 4) so we concatenate null values with real values of non blank cells.
Not sure if this will make the sheet load slower if you have too many records.
Hope this helps
Excel is not the same Google Sheets
=ARRAYFORMULA(TRIM(REGEXREPLACE(
TRANSPOSE(
QUERY(TRANSPOSE(IF(C2:F13<>"",C1:F1 & ", ","")),,99^99)
),
"((\s+)|(,\s*$))",
" "
)))
My sample
use:
=ARRAYFORMULA(REGEXREPLACE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
IF(C2:G<>"", C1:G1&" "&C2:G&",", )),,99^99))), ",$", ))

Adding a range of cells to one cell based on a condition

I have a sheet in Ms Excel with Loan details, where the loan status is either 'Paid' or 'Unpaid'. For every row, I want to add the amount value to cell C18 if the corresponding cell in status column reads "Unpaid".
eg. for row 10,
=IF(J10 ="Unpaid", $C$18+G10, $C$18+0) **{This does not work}**
How can I achieve this so as to use the formula for a couple of rows?
You might try ...
=C$18+(J10="Unpaid")*G10
This formula will add C18 to G10, but only if J10 says "Unpaid", otherwise, it will just add C18 to 0.
It can be "dragged down" for the other rows, and the '$' on C$18 will keep that cell fixed while the references for J and G will correspond to the row that the formula is in.
My guess from what you're saying is that you want to add column G only when the corresponding value in column J = "Unpaid".
If so, the formula you put in C18 is =SUMIFS(G:G,J:J,"Unpaid") or =SUMIFS(G10:G,J10:J,"Unpaid") if you want to start the sum at row 10.
You can't add to $c$10, only to a new column, lets say called 'balance'. There (column k) would be the formula =$k9+if($j10="Unpaid",$g10,0)
in Google Sheets:
=ARRAYFORMULA(IF(J10:J50="Unpaid"; C18+G10:G50; C18))

How to count the number of blank cells in one column based on the first blank row in another column

I have a spreadsheet set up with tv program titles in column B, the next 20 or so columns are tracking different information about that title. I need to count the number of blank cells in column R relating to the range in column B that contains titles (ie, up to the first blank row in column B.)
I can easily set up a formula to count the number of empty cells in a given range in column R, the problem is as I add more titles to the sheet I would have to keep updating the range in the formula [a simple =COUNTIF(R3:R1108, "")]. I've done a little googling of the problem but haven't quite found anything that fits the situation. I thought I would be able to get the following to work but I didn't fully understand what was going on with them and they weren't giving the expected results.
I've tried these formulas:
=ArrayFormula(sum(MIN("B3:B"&MIN(IF((R3:R)>"",ROW(B3:B)-1)))))
=ArrayFormula(sum(INDIRECT("B3:B"&MIN(IF((R3:R)>"",ROW(B3:B)-1)))))
And
=if(SUM(B3:B)="","",SUM(R3:R))
All of the above formulas give "0" as the result. Based on the COUNTIF formula I have set up it should be 840, which is a number I would expect. Currently, there are 1106 rows containing data and 840 is a reasonable number to expect in this situation.
Is this what you're looking for?
=COUNTBLANK(INDIRECT(CONCATENATE("R",3,":R",(3+COUNTA(B3:B)))))
This counts the number of non-blank rows in the B column (starting at B3), and uses that to determine the rows to perform COUNTBLANK in, in column R (starting at R3). CONCATENATE is a way to give it a range by adding strings together, and the INDIRECT allows for the range reference to be a string.
a proper way would be:
=ARRAYFORMULA(COUNTBLANK(INDIRECT(ADDRESS(3, 18, 4)&":"&
ADDRESS(MAX(IF(B3:B<>"", ROW(B3:B), )), 18, 4)))
or shorter:
=ARRAYFORMULA(COUNTBLANK(INDIRECT("R3:"&
ADDRESS(MAX(IF(B3:B<>"", ROW(B3:B), )), 18, 4))))
or shorter:
=ARRAYFORMULA(COUNTBLANK(INDIRECT("R3:R"&MAX(IF(B3:B<>"", ROW(B3:B), ))))

How to count a value in a range using array formula

I want to count the number of No in theses ranges F:R,BC:BN,CX:DI with array formula so if any one submit a new response containing No in these ranges it counts them
I tried using this formula
=ARRAYFORMULA(IF(ROW(E:E)=1,"NC",IF(LEN(E:E), IF(IFERROR(REGEXEXTRACT(TRANSPOSE(QUERY(TRANSPOSE(COUNTIFS(OR(DV:EG="No",BW:CH="No",U:AG="No"))),, 999^99)), "♦"))="♦", 1, 0), )))
but it didn't work, I also tried this formula:
=ARRAYFORMULA(IF(ROW(A:A)=1,"NC",IF(LEN(A:A)=0,IFERROR(1/0),COUNTIFS(F:R,"No")+COUNTIFS(BC:BN,"No")+COUNTIFS(CX:DI,"No"))))
But it counted all the value in the whole range
I need it to count the No row by row so at the end of every row under NC it shows the number of the No in these ranges F:R,BC:BN,CX:DI
Here is a spread sheet containing the data
https://docs.google.com/spreadsheets/d/1SksZv0h82j5oEZBj2AN5anDFr80AYNR5ettSwkpUKys/edit#gid=0
=ARRAYFORMULA({"NC"; IF(LEN(A2:A),
MMULT(IFERROR(LEN(REGEXEXTRACT({F2:R,BC2:BN,CX2:DI}, "No"))/
LEN(REGEXEXTRACT({F2:R,BC2:BN,CX2:DI}, "No")), 0),
TRANSPOSE(COLUMN(A1:AK1)^0)), )})

PHPExcel Protect a single column

I have issues with cell protection.
I would like to protect just one column, B for example.
So I tried:
$sheet->getProtection()->setSheet(true);
$highestRow = $sheet->getHighestRow();
$sheet->getStyle('A1:J2000)->getProtection()->setLocked( PHPExcel_Style_Protection::PROTECTION_UNPROTECTED );
for($i=1;$i<=$highestRow;$i++)
{
$sheet->getStyleByColumnAndRow(1,$i)->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_PROTECTED);
}
But it's really slow, and not good because if I need to open my sheet again
$highestRow = $sheet->getHighestRow(); will return "J".
Another solution would be to get the last non-empty column, do you know how to do that? Because getHighestRow(Column) return the columns unprotected or empty.
The loop is slow because you're applying the style to each individual cell, rather than to the range of cells demonstrated in your
$sheet->getStyle('A1:J2000)->getProtection()->setLocked( PHPExcel_Style_Protection::PROTECTION_UNPROTECTED );
line
: one call to set the style for a range of 1000 cells is more that 1000 times faster than applying it to each of 1000 cells individually.
$sheet->getHighestDataRow();
will return the highest row in the worksheet that contains actual data values
$sheet->getHighestDataColumn();
is the column equivalent
First you can protect complete sheet. After that you can uprotect others. This code will protect the first column and first
$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
$objPHPExcel->getActiveSheet()->getStyle('B2:Z400')->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);