0
votes

I have made a speadsheet with Google Sheet which contains two sheets:

Name of sheet 1: Start
Name of sheet 2: Playlist

I have made the following script:

function shuffleSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange("A4:C15");

// Randomizes the range
range.randomize();
}    

The script worked fine when I only had 1 sheet. Now I have two and I want the script to run on the sheet named Playlist.

I can't figure out how to do this. Please help.

Thanks.

1
Try a afor...loopTheMaster
I'm sorry but I don't know what you mean by that. Can you explain more? Thanks you.WJ496582
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… If you still can't figure it out, consider taking a basic JavaScript tutorial or crash course.TheMaster

1 Answers

2
votes

If you only want to run the code on the "Playlist" sheet this should work for you.

function shuffleSheet() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Playlist");
  var range = sheet.getRange("A4:C15");

  // Randomizes the range
  range.randomize(); 
}

I you want to run it on all sheets then you need to use a for loop.

function shuffleSheet() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();

  for (var i = 0; i < sheets.length; i++) {
    var sheet = sheets[i];
    var range = sheet.getRange("A4:C15");

    // Randomizes the range
    range.randomize(); 
  }
}