0
votes

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()."

1
Try openBYid and see, no sure what you have done and cause this issue or you have delete or rename the sheet USRdb?Kin Siang
The sheet USRdb does exist and has in the range A1:A values up to the row 418, it was giving that number before in the dialog, but now it appears like that for some reason. I havent change it.Diego Robles
Try break it down to two part, var ss= SpreadsheetApp.getActiveSpreadsheet() Then var SheetToMeassure = ss.getSheetByName("USRdb") , it first part also cause error, then really got problem.Kin Siang
I just tried what you said: function LastRowNumber(){ var ss = SpreadsheetApp.getActiveSpreadsheet(); var SheetToMeassure = ss.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 appear in the second part. In SheetToMeassure = ss.getSheetByName("USRdb")Diego Robles
Ya, maybe your sheet name contain space, double click on it and seeKin Siang

1 Answers

0
votes

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);

}