I have a sheet where there is a list of the other sheets in the spreadsheets with a link to them. The link looks like that:
=HYPERLINK(\"https://docs.google.com/spreadsheets/d/"+ssID+"/edit#gid="+sheetID+"\";"+"\""+name+"\")"
Note that the first sheet only contains these hyperlinks and a few references(=Test!B3 for example) to the other sheets and no direct Values.
When i try to get the last row with getLastRow() it always returns 0, disregarding the amount of rows actually filled with links/references. The same occurs when i use the here proposed code:
function getFirstEmptyRow(sheet) {
var range = sheet.getDataRange();
var values = range.getValues();
for (var row=0; row<values.length; row++) {
if (!values[row].join("")) break;
}
return (row+1);
}
It also always returns 1. So i came to the conclusion that hyperlinks and references do not count as Cell Value. Is there any way to get the last row with references/hyperlinks in it, getting the last row of the sheet that is actually used? The whole code of the function:
function restoreSheet(form)
{
try
{
var name = form.pRestore;
if (name != "")
{
var archive = SpreadsheetApp.openById('ID');
var sheet = archive.getSheetByName(name);
var list = archive.getSheetByName('list');
var values = list.getDataRange().getValues();
var destination = SpreadsheetApp.openById('ID');
var overview = destination.getSheetByName('cover sheet');
for (var i = 0; i < list.getLastRow(); i++)
{
if (values[i][0] == name)
{
var rowIndex = i + 1;
}
else if (i >= overview.getLastRow())
{
return false;
}
}
//erasing stuff on the archives
sheet.copyTo(destination).setName(name);
archive.deleteSheet(sheet);
list.deleteRow(rowIndex);
list.sort(1);
// adding stuff to the overview
var rowindex = getFirstEmptyRow(overview);
var ssID = ss.getId(); //ID of the spreadsheet for link creation
var oldSheet = ss.getSheetByName(name);
if (oldSheet != null)
{
var sheetID = oldSheet.getSheetId(); //ID of the sheet for link creation
}
else
{
Browser.msgBox(oldName + " was not found");
}
var link = "=HYPERLINK(\"https://docs.google.com/spreadsheets/d/" + ssID + "/edit#gid=" + sheetID + "\";" + "\"" + name + "\")";
overview.getRange(rowIndex + 1, 3).setValue(link); //Project Name (so that ppl who can only see the sheet can get to the right sheet
overview.getRange(rowIndex + 1, 4).setValue("='" + name + "'!B3"); //Project Owner
overview.getRange(rowIndex + 1, 5).setValue("='" + name + "'!H1"); //Group
overview.getRange(rowIndex + 1, 6).setValue("='" + name + "'!N1"); //Tags
overview.getRange(rowIndex + 1, 7).setValue("='" + name + "'!M11"); //Wanted
overview.getRange(rowIndex + 1, 8).setValue("='" + name + "'!F1"); //Status
}
else
{
Browser.msgBox("Not all required fields filled");
return false;
}
}
catch (e)
{
Browser.msgBox(e);
}
}
/**
* Function to get the first completely empty row
*/
function getFirstEmptyRow(sheet) {
var range = sheet.getDataRange();
var values = range.getValues();
for (var row=0; row<values.length; row++) {
if (!values[row].join("")) break;
}
return (row+1);
}