79157879

Date: 2024-11-05 06:26:58
Score: 0.5
Natty:
Report link

Improving onEdit Function

For better approach improving the function of onEdit.

Script modified

function onEdit(e) {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  var x = e.range.getA1Notation();
  SpreadsheetApp.getActiveSpreadsheet().toast(x);

    if(x == "A1:Z1000"){
    ss.moveActiveSheet(ss.getNumSheets());
    }
   }

This condition is for the testing of your post you will need to adjust depends on your dataset also if you edit on the cell the active sheet will not moved into the last row

if(x == "A1:Z1000"){
ss.moveActiveSheet(ss.getNumSheets());
}

on this part

let sheet = ss.getSheetByName("Sheet1").copyTo(ss).activate(); 

This line is not needed since it will be redundant with the manual duplication your doing on the spreadsheet.

Sample Output

1

2

3

Reference

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Patsytalk