To rename a Google Sheets tab with a cell’s MM/DD value from a different workbook, you can use Google Apps Script. Here’s an example code snippet that demonstrates how to achieve this:
function renameSheet() {
var sourceSpreadsheetId = "SOURCE_SPREADSHEET_ID";
var sourceSheetName = "SOURCE_SHEET_NAME";
var targetSpreadsheetId = "TARGET_SPREADSHEET_ID";
var targetSheetId = "TARGET_SHEET_ID";
// Get the MM/DD value from the source spreadsheet and sheet
var sourceSheet = SpreadsheetApp.openById(sourceSpreadsheetId).getSheetByName(sourceSheetName);
var cellValue = sourceSheet.getRange("A1").getDisplayValue(); // Modify the range as per your requirement
// Rename the target sheet in the target spreadsheet
var targetSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetId);
var targetSheet = targetSpreadsheet.getSheetById(targetSheetId);
targetSheet.setName(cellValue);
}
Here’s how you can use this code:
- Replace
"SOURCE_SPREADSHEET_ID"
with the ID of the spreadsheet that contains the source sheet with the MM/DD value. - Replace
"SOURCE_SHEET_NAME"
with the name of the source sheet that contains the MM/DD value. - Replace
"TARGET_SPREADSHEET_ID"
with the ID of the spreadsheet that contains the target sheet you want to rename. - Replace
"TARGET_SHEET_ID"
with the ID of the target sheet that you want to rename. You can find the sheet ID in the URL of the Google Sheets document.
After making these changes, you can run the renameSheet()
function from the Apps Script editor or by assigning it to a button or trigger. The target sheet in the target spreadsheet will be renamed with the MM/DD value from the source sheet.