Search code examples
javascriptgoogle-apps-scriptgoogle-sheetseditcells

Is there a way to edit the same cell across multiple Google Sheet Files?


I have about 40 different google sheet files that i need to change the color/date of a small little area every couple of months.

As far as i have found, there IS a way to edit the same cell across a sheets multiple pages. However, I have not found a way to edit the same cell across multiple sheets.

var color = Browser.inputBox("Enter the color");
var sheet = spreadsheetApp.openByUrl("Same link as if i was editing it actively from my browser");
sheet.getRange("M18").setBackground(color);

Any ideas would be appreciated! Thanks!


Solution

  • You could create an array of spreadsheet ID's, then loop through the array.

    function updateColor() {
      var spreadsheetIDs = ["ssID_One","ssID_Two","ssID_Three","ssID_etc"];
      var i,color="",sheet,thisID="",L=0;
      
      L = spreadsheetIDs.length;
    
      for (i=0;i<L;i++) {
        thisID=spreadsheetIDs[i];
        color = Browser.inputBox("Enter the color");
        sheet = SpreadsheetApp.openById(thisID).getSheetByName('sheetNameHere');
        sheet.getRange("M18").setBackground(color);
      };
    };