I would like to add rows based on a specific cell value yet that the rows will be added only below (or at) cells that answer a certain condition.
i tried to search Google but all i found was how to add rows after every other row.
function insertBlankRows() {
// version 1.1, written by --Hyde, 17 January 2023
// - see https://webapps.stackexchange.com/q/168794/269219
const range = SpreadsheetApp.getActiveSheet().getRange('X2:X');
const rowStart = range.getRow();
const rowNumbers = [];
const numRowsToInsert = range.getValues()
.flat()
.filter((value, index) => {
if (typeof value === 'number' && value > 1) {
rowNumbers.push(rowStart + index);
return true;
}
return false;
})
.map(numRows => numRows - 1);
insertBlankRows_(range.getSheet(), rowNumbers, numRowsToInsert);
}
/**
* Inserts numRowsToInsert blank rows in sheet after rowNumbers.
*
* @param {Sheet} sheet The sheet where to insert blank rows.
* @param {Number[]} rowNumbers The 1-indexed row numbers after which to insert blank rows.
* @param {Number[]} numRowsToInsert How many rows to insert after each rowNumbers.
*/
function insertBlankRows_(sheet, rowNumbers, numRowsToInsert) {
// version 1.0, written by --Hyde, 8 July 2021
// - see https://support.google.com/docs/thread/116344628?msgid=116435373
numRowsToInsert.reduceRight((_, numRows, index, array) => {
sheet.insertRowsAfter(rowNumbers[index], numRows);
}, null);
}
when i want to create something that will add rows only after specific text values (list).
for example:
Column A | Column B |
---|---|
dadada | 123456 |
dadada | 123456 |
bababa | 123456 |
i would like based on a certain cell that when the value in column A changes add rows there.
Column A | Column B |
---|---|
dadada | 123456 |
dadada | 123456 |
bababa | 123456 |
bababa | 123456 |