Reputation: 1
I'm a script newby and I'd like to automate the creation of rows underneath a cell every time the value of that certain cell is X
Whenever a Cell = WE, I'd like rows or subrows to be created underneath it with values: IT, ES, UK, NL, FR.
sample sheet can be found here: https://docs.google.com/spreadsheets/d/1TbYsbqFHmpFOdmj8vgFY9jeGUI1O212sJGb3Umh2fWE/edit?usp=sharing
Can anyone help? Should I be using appendrow?
Many thanks, Nathalie
Upvotes: 0
Views: 66
Reputation: 64140
Setup the onEdit trigger to run this function. Put WE somewhere and rows will be added and required values will be set.
function addingRows(e)
{
var addA=[['IT'], ['ES'], ['UK'], ['NL'], ['FR']];
var ss=e.source;
var sh=ss.getActiveSheet();
var col=e.range.getColumn();
var row=e.range.getRow();
if(e.value=='WE')
{
sh.insertRowsAfter(row,addA.length);
sh.getRange(row+1,col,addA.length,addA[0].length).setValues(addA);
}
}
Upvotes: 1