0
votes

Trying to combine two scripts here:

1) Get a cell value in a specific sheet

function getval() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('master'), true);
  spreadsheet.getCurrentCell().offset(2, 4).activate();
};

2) Create a new sheet and rename it according to cell value

spreadsheet.insertSheet(1);
spreadsheet.getActiveSheet().setName('');

The second step is where I struggle. How can I use the results of the getval function as a variable to place inside setName?

1

1 Answers

1
votes
function insertAndNameNewSheet() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('master');
  var name=sh.getCurrentCell().offset(2, 4).getValue();//2 rows down and 4 columns to the right
  ss.insertSheet(name,1);
}

insertSheet(name,index)

Best Practices