I have recorded the following macro:
function Test() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('10:16').activate();
spreadsheet.getActiveSheet().insertRowsBefore(spreadsheet.getActiveRange().getRow(), 7);
spreadsheet.getActiveRange().offset(0, 0, 7, spreadsheet.getActiveRange().getNumColumns()).activate();
spreadsheet.getActiveSheet().getRowGroup(9, 1).expand();
spreadsheet.getRange('10:10').activate();
spreadsheet.getRange('2:8').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
};
It creates a specific number of rows in a specific range. And then the same number of rows with data, starting from the second row of the table copies and pastes their values into the newly created rows.
Please help me change this script so that the number of rows copied and pasted, as well as the place where these rows are inserted, depends on the value in cell C1. The data to be copied is always taken starting from the second row.
Now the macros, let's say conditionally, is tied to the number 7: it inserts empty rows in the range from 10 to 16 (7 rows). Copies the values of 7 rows, starting from the second row, and pastes these values into the generated rows.
And I would like the script to take into account the value of cell C1 when performing these operations. And if, for example, C1 is equal to 10, then new empty rows should be created in the range from 13 to 22 rows (10 rows), then 10 rows of the table are copied, starting from the second row, and these rows are inserted into the previously created empty rows.
I understand that the introduction of a variable is necessary:
var N = spreadsheet.getRange('C1').getValue();
But how to implement the dependence of further steps on this variable, I just can not understand. I sincerely ask you to help me figure it out.
Here is an example of the sheet - https://docs.google.com/spreadsheets/d/170f0FC-pfXV7OoUlOxS-M7ZA_slC4e8j2oZJjEs47Xo/edit#gid=0
And the second question: Is it possible through a script to organize the selection of a value from a drop-down list if some of the values in it change, but there is also an unchanged part? That is, the drop-down list cell contains today's date (this part changes every day) and one of four time options (11:00, 14:00, 17:00 and 21:00) - this part does not change. And is it possible to prescribe in the script that it selects a value containing, for example, "11:00" in the drop-down list?