I have a spreadsheet: https://docs.google.com/spreadsheets/d/1df2cp4DsJvSeBvhsNjLgIa5x_RO1X7s_APRdFzU6jqQ/edit?usp=sharing
| | C
/**
* @param {GoogleAppsScript.Events.SheetsOnChange|GoogleAppsScript.Events.SheetsOnFormSubmit} e
*/
const onFormSubmitORonChange = e => {
const rg = SpreadsheetApp.getActiveRange(),
wd = rg.getWidth(),
sh = rg.getSheet(),
lc = sh.getLastColumn(),
numRows = Math.max(
rg
.offset(0, wd, 1, 1)
.getNextDataCell(SpreadsheetApp.Direction.UP)
.getRow() - 1,
1
),
numCols = lc - wd;
sh.getRange(2, wd + 1, numRows, numCols).autoFillToNeighbor(
SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES
);
};
This is a very common problem when dealing with auto-inserted data through sheets api or Google forms. The easiest solution would be to convert all your formulas into arrayformulas. For eg, Your formula in D2
=MID(C2,1,2)&"."&MID(C2,3,2)&".2020
can be modified as
In D1:
=ARRAYFORMULA({"Extracted Date";MID(C2:INDEX(C:C,COUNTA(C:C)),1,2)&"."&MID(C2:INDEX(C:C,COUNTA(C:C)),3,2)&".2020"})
OR using regex:
=ARRAYFORMULA({"Extracted Date";REGEXREPLACE(C2:INDEX(C:C,COUNTA(C:C)),"(\d{2})(\d{2}).*","$1.$2.2020")})
The table then becomes:
| | C | D |
|----+---------------------------------+---------------------------------------------------------------------------------------------------------------------|
| 1> | From IFTTT | =ARRAYFORMULA({"Extracted Date";MID(C2:INDEX(C:C,COUNTA(C:C)),1,2)&"."&MID(C2:INDEX(C:C,COUNTA(C:C)),3,2)&".2020"}) |
| 2> | 0809 1800 0909 0600 RLK Steiger | |
| 3> | 0809 1800 0909 0600 RLK Dvorak | |
| 4> | 0909 0600 0909 1800 UNIS Brando | |
Here the rest of D:D is auto filled automatically.
We use array literals on the header row: {"Extracted Date";Formula for rest of the column}
Whenever a new row comes, INDEX/COUNTA()
auto calculates the last row and automatically fills the formula upto last row. See here for a deeper explanation on INDEX/COUNTA
.