I want to name the workbook with the contents of cell A1. If cell A1 changes, the name of the workbook changes as well. I found the script that does this. BUT, if the contents of the cell is a formula ... (example: ="Hello World"&D42) There is no change and therefore no new name for the workbook.

So I put my formula in another cell (A2). And I wish that when the workbook is changed, the A2 content will be copied to A1 (values only) ... and the workbook will be named with the content of cell A1.

I can not make both functions work together

/* Script to copy paste value only */
    var source = ss.getRange('Todo!E2');
    source.copyTo(ss.getRange('Todo!A1'), {contentsOnly: true});
/* Script Edit the file name with the contents of cell A1 */

function onEdit(e) {  
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  var firstSheet = ss.getSheets()[0].getName();

  if( e.source.getActiveSheet().getName() == firstSheet ) {

  var r = e.source.getActiveRange();

  if( r.getA1Notation() == 'A1' )

  ss.setName(r.getValue());
}
};

Step 1 : I modify my workbook

Step 2 : A2 is modified and is copied to A1

Step 3 : A1 has changed, so the workbook is renamed with the content of A1

A big thank you to all !

0 Answers