How to determine the amount of rows inserted in a sheet with onChange trigger?Google Script to copy specific columns from one sheet to another sheets last row onEditMoving rows to another google spreadsheet based on a conditionGoogle Sheet Copy rows to different spreadsheetsHow to apply functions/formulas from last row after inserting a new row to google sheet?'Change' event triggers a function only if changes made in a specific sheet and not anywhere in the spreadsheetG-Sheets: Populate multiple cells from another sheet based on dropdown (multiple rows and columns)Google Spreadsheet : How to feed two sheets into a single pivot table?Google Sheets - Copy row script copies entire sheetMy Code Returns the correct Row (i think) but read writes to the wrong row Google Sheets ScriptHow to Update duplicate row in Google Script

Duck, duck, gone!

Why such a singular place for birding?

What organs or modifications would be needed to have hairy fish?

Should I be an author on another PhD student's paper if I went to their meetings and gave advice?

does 'java' command compile the java program?

Incomplete iffalse: How to shift a scope in polar coordinate?

Diminished data rate with logic output optoisolator

Which Catholic priests were given diplomatic missions?

What would happen if I build a half bath without permits?

Can I pay some of the cost of an activated ability lots of times to get more out of the effect?

Creating specific options in `Manipulate[]`

Approximate CO2 emissions for shipping a parcel from one location to another

Why are the wings of some modern gliders tadpole shaped?

What action is recommended if your accommodation refuses to let you leave without paying additional fees?

As a team leader is it appropriate to bring in fundraiser candy?

Convert a string of digits from words to an integer

Avoiding dust scattering when you drill

Why aren't faces sharp in my f/1.8 portraits even though I'm carefully using center-point autofocus?

Knights and Knaves: What does C say?

Replacing cord for IBM model M keyboard

Realistically, how much do you need to start investing?

Why does it seem the best way to make a living is to invest in real estate?

Is there any site with telescopes data?

Isn't the detector always measuring, and thus always collapsing the state?



How to determine the amount of rows inserted in a sheet with onChange trigger?


Google Script to copy specific columns from one sheet to another sheets last row onEditMoving rows to another google spreadsheet based on a conditionGoogle Sheet Copy rows to different spreadsheetsHow to apply functions/formulas from last row after inserting a new row to google sheet?'Change' event triggers a function only if changes made in a specific sheet and not anywhere in the spreadsheetG-Sheets: Populate multiple cells from another sheet based on dropdown (multiple rows and columns)Google Spreadsheet : How to feed two sheets into a single pivot table?Google Sheets - Copy row script copies entire sheetMy Code Returns the correct Row (i think) but read writes to the wrong row Google Sheets ScriptHow to Update duplicate row in Google Script






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I want to replicate some data from a spreadsheet to another. The first is often changing in size and the second one has a few columns from the first and then some other columns with it's own data.



I'd like to insert/delete rows in the second one depending on the rows inserted or deleted in the first one. They have to match the previous data.



I've tried to use an onChange trigger to detect when an INSERT_ROW or REMOVE_ROW changeType was detected. It works fine when it's just a row inserted, but not when they insert more than one. Also, when they insert a row and after they undo the action changeType is EDIT and not REMOVE_ROW. Fails.



Then I decided to add a hidden column with an index number in each row, so if there is a gap of numbers between row 5 and 6 it means that I have to insert 3 rows in the second sheet after the 5th row, then I rebuilt the index to check further changes... It also works if several rows have been removed.



That way seemed to work fine until I realised that the users can duplicate the rows or copy/paste the full row and then modify the data with new info BUT the index is also copied and when I check the differnce to check if any row has been removed, then it fails.



First try:



 if (event.changeType == 'INSERT_ROW' && tab =='Hoja 1') 
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i] =='')
destSheet.insertRowAfter(i+1);



if (event.changeType == 'REMOVE_ROW' && tab =='Hoja 1')
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i]-indexes[i+1] < -1 && indexes[i] != 0)
if (indexes[i] != lastRow)
destSheet.deleteRows(i+3,(indexes[i]-indexes[i+1])*-1-1)




for (var j = 0; j < lastRow-1; j++)
indexs.getCell(j+1, 1).setValue(j+1);

}


Second try:



function checkLines (sheet, destSheet) 
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i] =='')
destSheet.insertRowAfter(i+1);

if (indexes[i]-indexes[i+1] < -1 && indexes[i] != 0)
if (indexes[i] != lastRow)
destSheet.deleteRows(i+3,(indexes[i]-indexes[i+1])*-1-1)






I'd like to have a copy of the selected columns of the source sheet in a destination sheet and if the first one changes its rows the same should happen in the second one.



In some cases the destination doesn't get actualised and then the information written in the following column doesn't match with the info of the first columns.



Here is an link to an example of the source sheet:
https://docs.google.com/spreadsheets/d/19OnwKIEm2OFymjsjqeoQYWcA9BNAJTM0ap2rdpQlZoQ/edit?usp=sharing



And here the destination:
https://docs.google.com/spreadsheets/d/10vbMIqQE1miNfuJXQ1f_MSJnVs9MJrAOcg5_ZrAPWP8/edit?usp=sharing



I'll appreciate any suggestion...
And please let me know if you need further explanations... english is not my native language and I'm not sure if you understand my problem.



Thank you very much.



V.










share|improve this question


























  • How do they insert more than a row?

    – TheMaster
    Mar 28 at 21:10

















0















I want to replicate some data from a spreadsheet to another. The first is often changing in size and the second one has a few columns from the first and then some other columns with it's own data.



I'd like to insert/delete rows in the second one depending on the rows inserted or deleted in the first one. They have to match the previous data.



I've tried to use an onChange trigger to detect when an INSERT_ROW or REMOVE_ROW changeType was detected. It works fine when it's just a row inserted, but not when they insert more than one. Also, when they insert a row and after they undo the action changeType is EDIT and not REMOVE_ROW. Fails.



Then I decided to add a hidden column with an index number in each row, so if there is a gap of numbers between row 5 and 6 it means that I have to insert 3 rows in the second sheet after the 5th row, then I rebuilt the index to check further changes... It also works if several rows have been removed.



That way seemed to work fine until I realised that the users can duplicate the rows or copy/paste the full row and then modify the data with new info BUT the index is also copied and when I check the differnce to check if any row has been removed, then it fails.



First try:



 if (event.changeType == 'INSERT_ROW' && tab =='Hoja 1') 
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i] =='')
destSheet.insertRowAfter(i+1);



if (event.changeType == 'REMOVE_ROW' && tab =='Hoja 1')
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i]-indexes[i+1] < -1 && indexes[i] != 0)
if (indexes[i] != lastRow)
destSheet.deleteRows(i+3,(indexes[i]-indexes[i+1])*-1-1)




for (var j = 0; j < lastRow-1; j++)
indexs.getCell(j+1, 1).setValue(j+1);

}


Second try:



function checkLines (sheet, destSheet) 
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i] =='')
destSheet.insertRowAfter(i+1);

if (indexes[i]-indexes[i+1] < -1 && indexes[i] != 0)
if (indexes[i] != lastRow)
destSheet.deleteRows(i+3,(indexes[i]-indexes[i+1])*-1-1)






I'd like to have a copy of the selected columns of the source sheet in a destination sheet and if the first one changes its rows the same should happen in the second one.



In some cases the destination doesn't get actualised and then the information written in the following column doesn't match with the info of the first columns.



Here is an link to an example of the source sheet:
https://docs.google.com/spreadsheets/d/19OnwKIEm2OFymjsjqeoQYWcA9BNAJTM0ap2rdpQlZoQ/edit?usp=sharing



And here the destination:
https://docs.google.com/spreadsheets/d/10vbMIqQE1miNfuJXQ1f_MSJnVs9MJrAOcg5_ZrAPWP8/edit?usp=sharing



I'll appreciate any suggestion...
And please let me know if you need further explanations... english is not my native language and I'm not sure if you understand my problem.



Thank you very much.



V.










share|improve this question


























  • How do they insert more than a row?

    – TheMaster
    Mar 28 at 21:10













0












0








0








I want to replicate some data from a spreadsheet to another. The first is often changing in size and the second one has a few columns from the first and then some other columns with it's own data.



I'd like to insert/delete rows in the second one depending on the rows inserted or deleted in the first one. They have to match the previous data.



I've tried to use an onChange trigger to detect when an INSERT_ROW or REMOVE_ROW changeType was detected. It works fine when it's just a row inserted, but not when they insert more than one. Also, when they insert a row and after they undo the action changeType is EDIT and not REMOVE_ROW. Fails.



Then I decided to add a hidden column with an index number in each row, so if there is a gap of numbers between row 5 and 6 it means that I have to insert 3 rows in the second sheet after the 5th row, then I rebuilt the index to check further changes... It also works if several rows have been removed.



That way seemed to work fine until I realised that the users can duplicate the rows or copy/paste the full row and then modify the data with new info BUT the index is also copied and when I check the differnce to check if any row has been removed, then it fails.



First try:



 if (event.changeType == 'INSERT_ROW' && tab =='Hoja 1') 
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i] =='')
destSheet.insertRowAfter(i+1);



if (event.changeType == 'REMOVE_ROW' && tab =='Hoja 1')
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i]-indexes[i+1] < -1 && indexes[i] != 0)
if (indexes[i] != lastRow)
destSheet.deleteRows(i+3,(indexes[i]-indexes[i+1])*-1-1)




for (var j = 0; j < lastRow-1; j++)
indexs.getCell(j+1, 1).setValue(j+1);

}


Second try:



function checkLines (sheet, destSheet) 
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i] =='')
destSheet.insertRowAfter(i+1);

if (indexes[i]-indexes[i+1] < -1 && indexes[i] != 0)
if (indexes[i] != lastRow)
destSheet.deleteRows(i+3,(indexes[i]-indexes[i+1])*-1-1)






I'd like to have a copy of the selected columns of the source sheet in a destination sheet and if the first one changes its rows the same should happen in the second one.



In some cases the destination doesn't get actualised and then the information written in the following column doesn't match with the info of the first columns.



Here is an link to an example of the source sheet:
https://docs.google.com/spreadsheets/d/19OnwKIEm2OFymjsjqeoQYWcA9BNAJTM0ap2rdpQlZoQ/edit?usp=sharing



And here the destination:
https://docs.google.com/spreadsheets/d/10vbMIqQE1miNfuJXQ1f_MSJnVs9MJrAOcg5_ZrAPWP8/edit?usp=sharing



I'll appreciate any suggestion...
And please let me know if you need further explanations... english is not my native language and I'm not sure if you understand my problem.



Thank you very much.



V.










share|improve this question
















I want to replicate some data from a spreadsheet to another. The first is often changing in size and the second one has a few columns from the first and then some other columns with it's own data.



I'd like to insert/delete rows in the second one depending on the rows inserted or deleted in the first one. They have to match the previous data.



I've tried to use an onChange trigger to detect when an INSERT_ROW or REMOVE_ROW changeType was detected. It works fine when it's just a row inserted, but not when they insert more than one. Also, when they insert a row and after they undo the action changeType is EDIT and not REMOVE_ROW. Fails.



Then I decided to add a hidden column with an index number in each row, so if there is a gap of numbers between row 5 and 6 it means that I have to insert 3 rows in the second sheet after the 5th row, then I rebuilt the index to check further changes... It also works if several rows have been removed.



That way seemed to work fine until I realised that the users can duplicate the rows or copy/paste the full row and then modify the data with new info BUT the index is also copied and when I check the differnce to check if any row has been removed, then it fails.



First try:



 if (event.changeType == 'INSERT_ROW' && tab =='Hoja 1') 
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i] =='')
destSheet.insertRowAfter(i+1);



if (event.changeType == 'REMOVE_ROW' && tab =='Hoja 1')
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i]-indexes[i+1] < -1 && indexes[i] != 0)
if (indexes[i] != lastRow)
destSheet.deleteRows(i+3,(indexes[i]-indexes[i+1])*-1-1)




for (var j = 0; j < lastRow-1; j++)
indexs.getCell(j+1, 1).setValue(j+1);

}


Second try:



function checkLines (sheet, destSheet) 
for (var i = 0 ; i < indexes.length ; i++)
if (indexes[i] =='')
destSheet.insertRowAfter(i+1);

if (indexes[i]-indexes[i+1] < -1 && indexes[i] != 0)
if (indexes[i] != lastRow)
destSheet.deleteRows(i+3,(indexes[i]-indexes[i+1])*-1-1)






I'd like to have a copy of the selected columns of the source sheet in a destination sheet and if the first one changes its rows the same should happen in the second one.



In some cases the destination doesn't get actualised and then the information written in the following column doesn't match with the info of the first columns.



Here is an link to an example of the source sheet:
https://docs.google.com/spreadsheets/d/19OnwKIEm2OFymjsjqeoQYWcA9BNAJTM0ap2rdpQlZoQ/edit?usp=sharing



And here the destination:
https://docs.google.com/spreadsheets/d/10vbMIqQE1miNfuJXQ1f_MSJnVs9MJrAOcg5_ZrAPWP8/edit?usp=sharing



I'll appreciate any suggestion...
And please let me know if you need further explanations... english is not my native language and I'm not sure if you understand my problem.



Thank you very much.



V.







google-apps-script google-sheets google-apps-script-editor






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 20:41









Cooper

13.5k3 gold badges9 silver badges33 bronze badges




13.5k3 gold badges9 silver badges33 bronze badges










asked Mar 28 at 20:08









Victor Bove elrowfamilyVictor Bove elrowfamily

1




1















  • How do they insert more than a row?

    – TheMaster
    Mar 28 at 21:10

















  • How do they insert more than a row?

    – TheMaster
    Mar 28 at 21:10
















How do they insert more than a row?

– TheMaster
Mar 28 at 21:10





How do they insert more than a row?

– TheMaster
Mar 28 at 21:10












2 Answers
2






active

oldest

votes


















0
















You can use something like this:



function initRows() //run once before first use
var lastrow=SpreadsheetApp.getActiveSheet().getLastRow();
PropertiesService.getScriptProperties().setProperty('ROWS',lastrow);
return lastrow;


function getRows()
return PropertiesService.getScriptProperties().getProperty('ROWS');


function setRows(value)
PropertiesService.getScriptProperties().setProperty('ROWS',value);


function detectRowChange(e) //attach to onChange installable trigger
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var number=Math.abs(getRows()-sh.getLastRow());
var html=Utilities.formatString('Change Type: %s Number: %s', e.changeType,number);
var ui=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModelessDialog(ui, 'Change');
setRows(sh.getLastRow());



This utilizes a dialog to identify the type of change and the number of rows effected. You will probably want to customize it for your particular needs. Don't forget to run initRows() before setting up the trigger.



PropertiesService






share|improve this answer

























  • Thanks Cooper, but this solution only tells me how many rows have been added or removed, not the position.

    – Victor Bove elrowfamily
    Apr 1 at 9:37


















0
















The active range1 has the number of rows inserted.



Snippet:



function onChange(e)
if (e.changeType === 'INSERT_ROW')
const rng = SpreadsheetApp.getActiveRange();
const row = rng.getRow();//Row where insert row is done
const lrow = rng.getLastRow();//Last row in the newly active range
const numRows = 1+lrow-row;//number of rows inserted




Also look at adding developer metadata2 to rows, so that when they're moved, you might be able to recognize it.




I'd like to have a copy of the selected columns of the source sheet in a destination sheet and if the first one changes its rows the same should happen in the second one.




Easiest way is to just get all the data and paste it in the destination sheet(getValues and setValues).






share|improve this answer

























  • Hey TheMaster, thanks for your response. I'll try the second option (adding metadata) but it seems pretty complicated (I'm a beginner). I'll have a look.

    – Victor Bove elrowfamily
    Apr 1 at 9:33














Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406054%2fhow-to-determine-the-amount-of-rows-inserted-in-a-sheet-with-onchange-trigger%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0
















You can use something like this:



function initRows() //run once before first use
var lastrow=SpreadsheetApp.getActiveSheet().getLastRow();
PropertiesService.getScriptProperties().setProperty('ROWS',lastrow);
return lastrow;


function getRows()
return PropertiesService.getScriptProperties().getProperty('ROWS');


function setRows(value)
PropertiesService.getScriptProperties().setProperty('ROWS',value);


function detectRowChange(e) //attach to onChange installable trigger
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var number=Math.abs(getRows()-sh.getLastRow());
var html=Utilities.formatString('Change Type: %s Number: %s', e.changeType,number);
var ui=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModelessDialog(ui, 'Change');
setRows(sh.getLastRow());



This utilizes a dialog to identify the type of change and the number of rows effected. You will probably want to customize it for your particular needs. Don't forget to run initRows() before setting up the trigger.



PropertiesService






share|improve this answer

























  • Thanks Cooper, but this solution only tells me how many rows have been added or removed, not the position.

    – Victor Bove elrowfamily
    Apr 1 at 9:37















0
















You can use something like this:



function initRows() //run once before first use
var lastrow=SpreadsheetApp.getActiveSheet().getLastRow();
PropertiesService.getScriptProperties().setProperty('ROWS',lastrow);
return lastrow;


function getRows()
return PropertiesService.getScriptProperties().getProperty('ROWS');


function setRows(value)
PropertiesService.getScriptProperties().setProperty('ROWS',value);


function detectRowChange(e) //attach to onChange installable trigger
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var number=Math.abs(getRows()-sh.getLastRow());
var html=Utilities.formatString('Change Type: %s Number: %s', e.changeType,number);
var ui=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModelessDialog(ui, 'Change');
setRows(sh.getLastRow());



This utilizes a dialog to identify the type of change and the number of rows effected. You will probably want to customize it for your particular needs. Don't forget to run initRows() before setting up the trigger.



PropertiesService






share|improve this answer

























  • Thanks Cooper, but this solution only tells me how many rows have been added or removed, not the position.

    – Victor Bove elrowfamily
    Apr 1 at 9:37













0














0










0









You can use something like this:



function initRows() //run once before first use
var lastrow=SpreadsheetApp.getActiveSheet().getLastRow();
PropertiesService.getScriptProperties().setProperty('ROWS',lastrow);
return lastrow;


function getRows()
return PropertiesService.getScriptProperties().getProperty('ROWS');


function setRows(value)
PropertiesService.getScriptProperties().setProperty('ROWS',value);


function detectRowChange(e) //attach to onChange installable trigger
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var number=Math.abs(getRows()-sh.getLastRow());
var html=Utilities.formatString('Change Type: %s Number: %s', e.changeType,number);
var ui=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModelessDialog(ui, 'Change');
setRows(sh.getLastRow());



This utilizes a dialog to identify the type of change and the number of rows effected. You will probably want to customize it for your particular needs. Don't forget to run initRows() before setting up the trigger.



PropertiesService






share|improve this answer













You can use something like this:



function initRows() //run once before first use
var lastrow=SpreadsheetApp.getActiveSheet().getLastRow();
PropertiesService.getScriptProperties().setProperty('ROWS',lastrow);
return lastrow;


function getRows()
return PropertiesService.getScriptProperties().getProperty('ROWS');


function setRows(value)
PropertiesService.getScriptProperties().setProperty('ROWS',value);


function detectRowChange(e) //attach to onChange installable trigger
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var number=Math.abs(getRows()-sh.getLastRow());
var html=Utilities.formatString('Change Type: %s Number: %s', e.changeType,number);
var ui=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModelessDialog(ui, 'Change');
setRows(sh.getLastRow());



This utilizes a dialog to identify the type of change and the number of rows effected. You will probably want to customize it for your particular needs. Don't forget to run initRows() before setting up the trigger.



PropertiesService







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 22:34









CooperCooper

13.5k3 gold badges9 silver badges33 bronze badges




13.5k3 gold badges9 silver badges33 bronze badges















  • Thanks Cooper, but this solution only tells me how many rows have been added or removed, not the position.

    – Victor Bove elrowfamily
    Apr 1 at 9:37

















  • Thanks Cooper, but this solution only tells me how many rows have been added or removed, not the position.

    – Victor Bove elrowfamily
    Apr 1 at 9:37
















Thanks Cooper, but this solution only tells me how many rows have been added or removed, not the position.

– Victor Bove elrowfamily
Apr 1 at 9:37





Thanks Cooper, but this solution only tells me how many rows have been added or removed, not the position.

– Victor Bove elrowfamily
Apr 1 at 9:37













0
















The active range1 has the number of rows inserted.



Snippet:



function onChange(e)
if (e.changeType === 'INSERT_ROW')
const rng = SpreadsheetApp.getActiveRange();
const row = rng.getRow();//Row where insert row is done
const lrow = rng.getLastRow();//Last row in the newly active range
const numRows = 1+lrow-row;//number of rows inserted




Also look at adding developer metadata2 to rows, so that when they're moved, you might be able to recognize it.




I'd like to have a copy of the selected columns of the source sheet in a destination sheet and if the first one changes its rows the same should happen in the second one.




Easiest way is to just get all the data and paste it in the destination sheet(getValues and setValues).






share|improve this answer

























  • Hey TheMaster, thanks for your response. I'll try the second option (adding metadata) but it seems pretty complicated (I'm a beginner). I'll have a look.

    – Victor Bove elrowfamily
    Apr 1 at 9:33
















0
















The active range1 has the number of rows inserted.



Snippet:



function onChange(e)
if (e.changeType === 'INSERT_ROW')
const rng = SpreadsheetApp.getActiveRange();
const row = rng.getRow();//Row where insert row is done
const lrow = rng.getLastRow();//Last row in the newly active range
const numRows = 1+lrow-row;//number of rows inserted




Also look at adding developer metadata2 to rows, so that when they're moved, you might be able to recognize it.




I'd like to have a copy of the selected columns of the source sheet in a destination sheet and if the first one changes its rows the same should happen in the second one.




Easiest way is to just get all the data and paste it in the destination sheet(getValues and setValues).






share|improve this answer

























  • Hey TheMaster, thanks for your response. I'll try the second option (adding metadata) but it seems pretty complicated (I'm a beginner). I'll have a look.

    – Victor Bove elrowfamily
    Apr 1 at 9:33














0














0










0









The active range1 has the number of rows inserted.



Snippet:



function onChange(e)
if (e.changeType === 'INSERT_ROW')
const rng = SpreadsheetApp.getActiveRange();
const row = rng.getRow();//Row where insert row is done
const lrow = rng.getLastRow();//Last row in the newly active range
const numRows = 1+lrow-row;//number of rows inserted




Also look at adding developer metadata2 to rows, so that when they're moved, you might be able to recognize it.




I'd like to have a copy of the selected columns of the source sheet in a destination sheet and if the first one changes its rows the same should happen in the second one.




Easiest way is to just get all the data and paste it in the destination sheet(getValues and setValues).






share|improve this answer













The active range1 has the number of rows inserted.



Snippet:



function onChange(e)
if (e.changeType === 'INSERT_ROW')
const rng = SpreadsheetApp.getActiveRange();
const row = rng.getRow();//Row where insert row is done
const lrow = rng.getLastRow();//Last row in the newly active range
const numRows = 1+lrow-row;//number of rows inserted




Also look at adding developer metadata2 to rows, so that when they're moved, you might be able to recognize it.




I'd like to have a copy of the selected columns of the source sheet in a destination sheet and if the first one changes its rows the same should happen in the second one.




Easiest way is to just get all the data and paste it in the destination sheet(getValues and setValues).







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 29 at 11:34









TheMasterTheMaster

15.9k3 gold badges14 silver badges40 bronze badges




15.9k3 gold badges14 silver badges40 bronze badges















  • Hey TheMaster, thanks for your response. I'll try the second option (adding metadata) but it seems pretty complicated (I'm a beginner). I'll have a look.

    – Victor Bove elrowfamily
    Apr 1 at 9:33


















  • Hey TheMaster, thanks for your response. I'll try the second option (adding metadata) but it seems pretty complicated (I'm a beginner). I'll have a look.

    – Victor Bove elrowfamily
    Apr 1 at 9:33

















Hey TheMaster, thanks for your response. I'll try the second option (adding metadata) but it seems pretty complicated (I'm a beginner). I'll have a look.

– Victor Bove elrowfamily
Apr 1 at 9:33






Hey TheMaster, thanks for your response. I'll try the second option (adding metadata) but it seems pretty complicated (I'm a beginner). I'll have a look.

– Victor Bove elrowfamily
Apr 1 at 9:33



















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406054%2fhow-to-determine-the-amount-of-rows-inserted-in-a-sheet-with-onchange-trigger%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript