Home > OS >  I can't unblock the error "Exception: Please select an active sheet first."
I can't unblock the error "Exception: Please select an active sheet first."

Time:02-16

I'm doing the Fundamentals of Apps Script course by Google and I'm encountering the following error:

"Exception: Please select an active sheet first. duplicateAndOrganizeActiveSheet @ Code.gs:7"

I've literally just pasted what the instructions said, so I don't understand what I'm doing wrong. The instructions said to paste the following code and run the function called "duplicateAndOrganizeActiveSheet()" to duplicate the active sheet.

    function renameSpreadsheet() {
  var mySS = SpreadsheetApp.getActiveSpreadsheet();
  mySS.rename("2017 Avocado Prices in Portland, Seattle");
}
function duplicateAndOrganizeActiveSheet() {
  var mySS = SpreadsheetApp.getActiveSpreadsheet();
  var duplicateSheet = mySS.duplicateActiveSheet();
}

However, I'm not able to run it because it gives me this error. I've read other posts and tried many things but I can't seem to find what's wrong with the code.

I'd appreciate help unblocking this so I can continue with the course. Thanks so much!

CodePudding user response:

Issue and solution:

First, I think that your script has no issue.

From your error message of "Exception: Please select an active sheet first. duplicateAndOrganizeActiveSheet @ Code.gs:7", I thought that in your situation, the link of the container-bound script (I think that in this case, it's script editor.) and Google Spreadsheet might be broken. For example, when such a situation occurs, an error like Please select an active sheet first. occurs.

In this case, please close Google Spreadsheet and the script editor. And, please open Google Spreadsheet and open the script editor, and run duplicateAndOrganizeActiveSheet again.

If this solution couldn't resolve the issue of Please select an active sheet first., please create a new Google Spreadsheet, open the script editor of the created Google Spreadsheet, please copy and paste your script, and run the script again.

  • Related