Google Apps Script: onEdit, Google Sheets
Sometimes you want to be able to automatically move a row from one sheet to another based on the value of a certain cell.
The Example
One of the first things that come to mind, and I am sure it does for you dear reader, is when I took advantage of the Great Chicken Transformation back in, oh, 2019, I believe.
Folk kept turning into chickens, while other folk were wanting eggs. It just so happened that I had the farm to make it all happen.
First, though, I needed to keep a tab of every person I knew and if they turned into a chicken. If they did, then they were destined for the pen.
…Note to self: it may be late at night, but dam Yagi, your analogies are tight!
Google Sheets and Google Apps Script to the rescue.
So first off I set up a sheet named: Plague. Here I put all the people I knew, so I could watch em good and propper.
Next, I set up a sheet named Farm. These are for the people who turned into chickens. No harm in profiting from a few newly formed egg layers, right?
Whenever a new transformation occurs, I find the person on the Plague sheet and then select “Yes” to say that they have turned into a chicken and will now be spending their days on the farm. Upon editing (onEdit) this cell to “Yes”, the row is copied and pasted to the Farm sheet.
Just like this: