Home > Mobile >  How would I add a new row above A2 when A2 is edited
How would I add a new row above A2 when A2 is edited

Time:01-26

I'm setting up a sheet for inventory info within Google Sheets; I'd like to add a new row above the edited one when someone signs out inventory automatically.

for example, when someone goes to check out an item, it should show the last row and last date entered

After someone enters their info, it should insert a new row with the existing formatting and alternating colors settings

I have already tried doing this manually by right-clicking on A2 and inserting above, maybe I did something wrong, but it inserted the new row with default colors and formatting. It may just be cosmetic, but it means something to me, at least.

CodePudding user response:

function onEdit(e) {
  const sh = e.range.getSheet();
  if(sh.getName() == "Your Sheet Name" && e.range.columnStart == 1 && e.range.rowStart == 2 && e.value) {
    sh.insertRowBefore(2);
  }
}
  •  Tags:  
  • Related