Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138279

Google Script Editing

$
0
0

I'm currently working on a project in google sheets and trying to create a script that will rename the tab of every new sheet based off a cell value inside the main sheet. Say for instance the ticket number in cell C7 would be what displays on the tab. I've done everything so far with a macro which leads me to my next question. Do i just add this at the bottom of all the code already there?

Here is what i have so far

function onEdit(e) {
  var ss = SpreadsheetApp.getActive()          //gets the active spreadsheet
  var sheet = SpreadsheetApp.getActiveSheet()  //gets the active sheet
  var cell = ss.getActiveRange()               //gets the active cell
  var cellContent = cell.getValue()            //gets the value of the active cell

  if(cellContent === 'BOXCHECKED') 
 {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('B1:H4').activate();
  var currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
  currentCell.activateAsCurrentCell();
  currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
  currentCell.activateAsCurrentCell();
  spreadsheet.getRange('B1:H55').activate();
  spreadsheet.insertSheet(1);
  spreadsheet.getRange('\'Quote Sheet\'!B1:H55').copyTo(spreadsheet.getActiveRange().rename spreadsheet '\' Quote Sheet\'H5') SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
  spreadsheet.getRange('\'Quote Sheet\'!B1:H55').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
  spreadsheet.getActiveSheet().hideSheet();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Data Sheets'), true);
  spreadsheet.getRange('2:35').activate();
  spreadsheet.getActiveSheet().insertRowsBefore(spreadsheet.getActiveRange().getRow(), 34);
  spreadsheet.getActiveRange().offset(0, 0, 34, spreadsheet.getActiveRange().getNumColumns()).activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Quote Sheet'), true);
  spreadsheet.getRange('B11').activate();
  currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.NEXT).activate();
  currentCell.activateAsCurrentCell();
  currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.NEXT).activate();
  currentCell.activateAsCurrentCell();
  currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.NEXT).activate();
  currentCell.activateAsCurrentCell();
  currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
  currentCell.activateAsCurrentCell();
  currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
  currentCell.activateAsCurrentCell();
  currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.UP).activate();
  currentCell.activateAsCurrentCell();
  spreadsheet.getRange('B12:z44').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Data Sheets'), true);
  spreadsheet.getRange('\'Quote Sheet\'!B12:z44').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Quote Sheet'), true);
   spreadsheet.getRangeList(['C5:C10', 'H6:H10', 'B12:B44','D12:E44', 'H49:H50','B51:E55']).activate();
  spreadsheet.setCurrentCell(spreadsheet.getRange('H49'));
  spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
  spreadsheet.getRange('C5').activate();
     SpreadsheetApp.getActive();
  spreadsheet.getRange('G53').activate();
  spreadsheet.getCurrentCell().setValue('False')
}

};

};


Viewing all articles
Browse latest Browse all 138279

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>