简体   繁体   中英

Google Sheets function to rename sheet to equal cell value

I'm trying to get my sheet names to equal cell values, whether it be text or numbers, but I've come up short. After numerous google searches, and testing, this is as close as I've gotten to an answer.

function myFunction() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[1]
  var cell = sheet.getRange("A2")
  sheets[3].setName(cell);
}

You need to getValue ¹ from the range you got.

function myFunction() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[1]; //Sheet 2
  var cell = sheet.getRange("A2");//Sheet2!A2    
  var value = cell.getValue();//Added
  sheet.setName(value);//Sheet2 name changed
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM