I am using a google sheet in which a new row is added by inserting Col A thru a third party app. Once Col A is added I wish to copy the formula from the remaining row cells above to auto calculate the values using the formulas in that row.
ArrayFormula doesn't help as I don't want to have the rows created in advance before Col A is populated.
Any script which can do this?
What you are looking for can be achieved with a formula. I have created a quick sheet to demonstrate this.
Cell B1 contains the following formula:
={"Formula";ifna(arrayformula(filter(A2:A, A2:A<>"")*5))}
This formula defines the header (meaning that it is placed in the first row, ultimately not affecting any third party data inputs), and then uses an array formula for the rest of the column. This formula works because of the filter. That filters out any cells that are not blank and multiplies them by 5. The IFNA portion ensures that if there is no data at all, the second row is still left completely blank. This was verified with a script I wrote to simulate a data entry.
function test() {
SpreadsheetApp.getActive().getActiveSheet().appendRow([Math.random()]);
}
This script is simple, and uses the appendRow() method to simulate what a third party entry would do. I used this script, and the result is displayed in the screenshot above. This shows that an appended row will still populate the next blank row, despite there being an array formula in cell B1. Using this logic, it is possible to change the formula to populate the actual data that you need.
Related
I would like to have a script that runs upon change in values to the sheet. What I have setup on my sheet is a few cells in a column that can have dynamic values typed into one of them (ex. J6:J10). I would like the script to run and check for a dynamic value in one of the cells, which it would then use that value in a formula contained in a different cell (I6) to calculate a formula similar to this: =ROUND(J6/E6,2). Cell J6 being dynamic.
I need the formula to be dynamic to match whichever J cell row has data and correlate to the E cell row
I was only able to get the sheet setup with its basic layout. I am still missing a working script that functions with the proper dynamic formula
If only 1 of the cells in J6:J10 has the value which you want to work with you could use in I6:
=ROUND(SUM(J6:J10)/E6,2)
What about this? It calculates all the ratios, and FILTER if J is empty; and finds the minimum ratio with MIN:
=IFNA(MIN(FILTER(INDEX(J6:10/E6:E10),J6:J10<>"")))
I have a spreadsheet with multiple sheets.
Sheet A is generated from a template, and it is where users will enter in data to be formatted into a report; it will be deleted after that report is submitted.
As people enter info into Column A of Sheet A, they don't have to enter client information if we already have them entered in this spreadsheet, but otherwise they need to go over to Sheet B and enter it in.
To make it easier for them (so they don't have to check every time, or go back and enter info later after getting an error generating the report), I have used conditional formatting. The way it works is, column Z is set up as a helper column, and uses a "COUNTIF" function to check if the client ID in Sheet A, Column A is found in Sheet B, Column C. Sheet A Column Z returns 0 or 1 (or, theoretically, more than one if we had duplicates), and then Sheet A column A has conditional formatting based on Column Z's value-- if the client is already in, the cell for client ID turns green after they type it; if not, it turns red.
It works great! However, I am adding scripts to these sheets, and looping through them. This helper column is filled from Z1 to Z1000, which means I can't use sheet.maxRow() to get the last row.
I see plenty of workarounds on the script side, but I was wondering if anyone has a clever way to input a value into the helper column Z ONLY IF the corresponding cell (same row) in column A has a value using spreadsheet formulas.
I suspect that an array formula with a filter might do it, but I have little experience with either and can't get anything to work out.
Thanks for your help!
You can use this expression with INDEX, MAX and ROW to make an ARRAYFORMULA only expandable until the last cell with value in column:
A2:INDEX(A2:A,MAX(ROW(A2:A)*(A2:A<>"")))
It will go from A2 to the maximum number of row in A in which A is different than null (that's why both conditions are multiplied).
Then you can set a formula like this in Z2 (check the ranges in case something is not right from reading your text, and delete all other formulas in Z too in case you weren't using an arrayformula already):
=BYROW(A2:INDEX(A2:A,MAX(ROW(A2:A)*(A2:A<>""))),LAMBDA(each,IF(each="","",COUNTIF('Sheet B'!C:C,each))))
I go to the community to find out if there is a solution to my problem which I detail below, I have a data matrix which grows from cell to cell along rows, there are rows that have more data than others and through the formula that I will leave at the end I can obtain the last 3 values of each row up to that point the formulas fulfill their function but when I try to add the Arrayformula I cannot make the formulas work so that they are completed automatically, I would appreciate if you could help me with this problem.
Google Sheet
Here is a possible solution, assuming there are no blank cells between the non-blank cells:
=ArrayFormula(vlookup(
row(C2:C11),
{row(C2:C11),C2:I11},
mod(sequence(rows(C2:C11),3,0),3)+mmult(if(C2:I11<>"",1,0),sequence(COLUMNS(C2:I11),1,1,0))-1,
0))
I'm filtering a larger sheet into a smaller sheet using the =FILTER formula. I set up my filter successfully, like so:
=FILTER(form!A3:M3, NOT(ISBLANK(form!A3:M3)))
My only condition was that I filter in results from the larger sheet to the smaller one as long as it's not empty, but that point aside, the problem is this:
Once the data is in the smaller sheet, I want to be able to edit cells in the smaller sheet ONLY. Right now, when I edit a cell in the smaller sheet, it errs because I'm overwriting the =FILTER result.
I know I can "copy + paste as values only" but I'm wondering if there's a formula I can combine with my current formula that would output the results of =FILTER automatically as values and not the result of the said formula. I have tried to use =TO_TEXT and =TEXT in conjunction with my formula to no result.
no, such functionality does not exist. most likely your only possible option (apart from CTRL+C ... CTRL+SHIFT+V) is to use FILTER via script to print the result into cells as values instead of reference.
I want to calculate the quotient of the cells in E and D rows, the logic is if both cells contains valid values then calculate otherwise do not do anything.
So far this is my formula:
={"OR (Open Rate)";ARRAYFORMULA(IFERROR(E2:E/D2:D))}
This works fine as it doesn't add value to the cell. But when I use the getLastRow() function on script editor, I get almost the 1000th cell on my empty sheet.
I suspect that the formula I am using is inserting a space or falsey values on each cell. How can I leave the cell blank if it doesn't meet my logic expression?
={"OR (Open Rate)";ARRAYFORMULA(IFERROR(E2:INDEX(E2:E,COUNTA(E2:E))/D2:INDEX(D2:D,COUNTA(E2:E))))}