Diego Robles
Diego Robles

Reputation: 15

Error Sheet not found in Google Sheets Script

I made this code in a google sheet script and worked fine, but for some reason all the sudden it shows the error "Sheet not found" but nothing has changed, the sheets have the same name as when I tried the funtion before and the values are not empty, the sheet USRdb DO exist:

function LastRowNumber(){

var SheetToMeassure = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("USRdb"); 
var RangeToMeassure = SheetToMeassure.getRange("A1:A").getValues();
var LastRow = RangeToMeassure.filter(String).length;


var ui = SpreadsheetApp.getUi();

ui.alert("Number of the last row: " + LastRow);

}

The error shown:

12:56:37 PM Error   
Exception: Sheet 400456734 not found
LastRowNumber   @ Code.gs:55

Where it says Code.gs:55 is referring to the line that starts with "var hojaa = SpreadsheetApp.getActiveSpreadsheet()."

Upvotes: 0

Views: 2146

Answers (1)

Diego Robles
Diego Robles

Reputation: 15

I have an update: I did what Kin Siang suggested but didn't work, but also I added .activate(); at the end after "getSheetByName("USRdb")" and now it works. Thank you all for the assistance!. Here is the code made again and working:

function LastRowNumber(){

var ss = SpreadsheetApp.getActiveSpreadsheet();
var SheetToMeassure = ss.getSheetByName("USRdb").activate();
var RangeToMeassure = SheetToMeassure.getRange("A1:A").getValues();
var LastRow = RangeToMeassure.filter(String).length;


var ui = SpreadsheetApp.getUi();

ui.alert("Number of the last row: " + LastRow);

}

Upvotes: 0

Related Questions