T
T
TomasF2021-08-27 17:43:15
Google Apps Script
TomasF, 2021-08-27 17:43:15

How to solve "TypeError: Cannot read property 'getRange' of undefined" error?

My task is to copy information from cell 1 of the sheet and transfer it to cell 2 of the sheet using a script, the trigger for which will be the value of the flag "true".
For ease of solving this problem, I first saved a macro that copies and pastes information, and then, through the script editor, inserted 2 lines of code into it as a trigger, but an error occurs, and I have not yet found how to fix it. Ask for help from knowledgeable people.

function Rt() {

  if(spreadsheet.getRange(6, 6).isChecked()===true){
  
    var spreadsheet = SpreadsheetApp.getActive();
    spreadsheet.getRange('A3').activate();
    spreadsheet.setActiveSheet(spreadsheet.getSheetByName('ae'), true);
    spreadsheet.getRange('A3').activate();
    spreadsheet.getActiveSheet().insertRowsAfter(spreadsheet.getActiveRange().getLastRow(), 1);
    spreadsheet.getActiveRange().offset(spreadsheet.getActiveRange().getNumRows(), 0, 1, spreadsheet.getActiveRange().getNumColumns()).activate();
    spreadsheet.setActiveSheet(spreadsheet.getSheetByName('dr'), true);
    spreadsheet.setActiveSheet(spreadsheet.getSheetByName('ae'), true);
    spreadsheet.getRange('dr!A3').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
    spreadsheet.getRange(6, 6).uncheck();
    }
};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question