0

I have a simple need to copy a range (E4:G4) and paste it X rows below, determined by the value of a cell, C2. I think I may be misunderstanding the offset function since when I run the routine, I get a "range not found" error, presumably because "dest" is not defined properly. Any suggestions?


function macrotest() {
  var spreadsheet = SpreadsheetApp.getActive();
  var rowoffset = spreadsheet.getRange("C2").getValue()
  var cell = spreadsheet.getRange("E4");
  var dest = cell.offset(rowoffset,1) 
  spreadsheet.getRange(dest).activate();
  spreadsheet.getRange('E4:G4').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
};

0

To solve the error

change

spreadsheet.getRange(dest).activate();

to

dest.activate();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.