I'm trying to make a sheet where when you change the text in a cell it changes the name of the current tab.
I currently have a simple script that works fine for just text, but I'm trying to use the built in date picker. For example when I type in "test" the tab is renamed to "test" but when I use the date picker and choose "4-6-22" it changes the tab name to "44657". Is there anyway to get it to rename the tab to just "4-6-22"?
This is the script I'm using
function onEdit(e) {
if(e.range.getA1Notation() == 'B3'){
SpreadsheetApp.getActiveSheet().setName(e.value);
}
}
CodePudding user response:
If you want a specific format
function onEdit(e) {
if(e.range.getA1Notation() == 'B3'){
if (!isNaN(Date.parse(e.value))){
SpreadsheetApp.getActiveSheet().setName(Utilities.formatDate(new Date(e.range.getDisplayValue()), Session.getScriptTimeZone(), "MMM dd yyyy"))
}
else{
SpreadsheetApp.getActiveSheet().setName(e.value);
}
}
}
CodePudding user response:
Probably this will work:
function onEdit(e) {
if(e.range.getA1Notation() == 'B3'){
SpreadsheetApp.getActiveSheet().setName(e.range.getDisplayValue());
}
}