how to rename sheets with macro

427 Views Asked by At

I want to create a macro in Google Spreadsheet which allows me to rename sheets with variable data.

First I've added a macro that duplicates my sheet 'BLANCO' 6 times, I works well.

I've created a sheet named DATA, in cells A1 to A6, I've added names. It works to rename the sheets to these names, but the macro uses the exact name and not the link to this cell. For example: DATA!A1 = Andreas In stead of referring to DATA!A1, it reffers to the data in this cell. So if I change this name "Andreas" to "Aster", de macro will still use the initial name (Andreas).

Here's the script of the macro:
printscreen

1

There are 1 best solutions below

0
Cooper On
function renameSheet() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  const ui = SpreadsheetApp.getUi();
  let resp = ui.prompt(`Current Sheet is ${sh.getName()} Enter new name or cancel`,ui.ButtonSet.OK_CANCEL);
  if(resp.getSelectedButton == ui.ButtonSet.OK_CANCEL) {
    sh.setName(resp.getResponseText());
  }
}