Skip to content
Advertisement

How to send/archive a row of data from one sheet to another through trigger?

JavaScript

I would like for a way to send a row of data from a sheet (Sheet) to another (Sheet Archive). If “Archive” is written in the 2nd column of a row, it sends the data to the archive sheet.

I want the data to stack one row after another. Say I archive row #20 in Sheet #1, I want it to send the data to row #9. If I archive row #21, 22, then 30, 31, etc. it should stack the archived rows one after the other, so in rows #9, 10, 11, 12, 13 etc. of the archive.

The code I have used to work but then I redesigned the sheets and they stopped working. When I type archive, it deletes it from Sheet #1 but then in the archive sheet it’s missing. So it’s “sending” it but it’s not showing up or pasting it properly. Is there a better way?

Thanks

Advertisement

Answer

I’ve cleaned you code a bit but seems mostly fine. Isntead of using getActiveRange and getActiveSheet, use the range provided by trigger argument. This is what it would look like:

JavaScript

I’ve also moved the way you tested for options and used strict equality (be careful with this).

References

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement