0
votes

i want to copy one sheet in a Google Spreadsheet "x" times in the same spreadsheet. I want them to have a simple number that counts up (first sheet is "1", second needs to be, "2", ... The "x" is a value in one of the sheets. The only code i founded so far is to duplicate a sheet:

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('1').copyTo(ss);

but i do not find how to put this in a:

 for (var i = 0; i < "X"; i++)...

code.

Anyone?

Thx!

1
I recommend reviewing JavaScript tutorials and reviewing the Apps Script API reference. There are methods and documentation for those methods that demonstrate how one gets a value from a range on a sheet. Outside of working with Google-specifics, you're just writing Javascript (v1.6)tehhowch

1 Answers

0
votes

Assuming you are copying sheet 1 and need 2 through x.

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var x = ss.getSheetByName('1').getRange("A1").getValue(); //get x from wherever you keep it
    for (var i = 1; i < x; i++) {
        ss.getSheetByName('1').copyTo(ss).setName(i+1);
    }