0
function _1() {
  var spreadsheet = SpreadsheetApp.getActive();
  var numSheets = SpreadsheetApp.getActiveSpreadsheet().getSheets().length
  var s1 = numSheets-1
  var s2 = numSheets-2

  spreadsheet.getSheetByName('bos').showSheet()
  .activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('bos'), true);

  spreadsheet.duplicateActiveSheet();
  spreadsheet.getActiveSheet().setName(s1);

  spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(17, criteria);
  spreadsheet.getRange('N6:T115').activate();

  spreadsheet.setActiveSheet(spreadsheet.getSheetByName(s2), true);
  spreadsheet.getRange('B6').activate();

  spreadsheet.getRange("s2!n6:t115").copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);

};

getRange("s2!n6:t115") gives this error:

Range not found

How can I fix it?

3
  • Welcome to Web Applications. The problem is "s2!n6:t115". Please bear in mind that sheet names are case sensitive. If you need further help, please edit the question to add more details (in this case add the sheet name exactly as it's shown on the screen) and a brief description of your search efforts as is suggested in How to Ask.
    – Rubén
    Nov 5 '21 at 14:37
  • Expanding on the point made by @Rubén... getRange("s2!n6:t115") infers that "s2" is a string and is the literal name of a sheet. There are many ways to manage this but one choice is something like var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(s2), then source.getRange("n6:t115").blah.blah. On a tangent, I am a relative novice with these things but I found the script hard to follow because every spreadsheet assignment is dynamic. I don't know the effect on performance but it would be easier to follow if you used var or const to assign sheets.
    – Tedinoz
    Nov 11 '21 at 0:02
  • @aky Did you resolve this problem, or are you still looking for help?
    – Tedinoz
    Dec 9 '21 at 21:55

Your Answer

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

Browse other questions tagged or ask your own question.