I have a Sheet that gets self-refreshing data from an external source. This Sheet which may not have the same lastRow or lastColumn. I need to find a quickest way to determine what is the true lastRow and true lastColumn of the sheet that contains data. I need to exclude cells containing formulas or data validations. Also, as the data refreshes, the rows count and columns count change everytime and therefore sometimes the getLastRow()
and getLastColumn()
donot work correctly but include blanks.
I have seen some code which requires you to input a particular column or row number inorder to identify its last data row or data column. I want to know if there is a way to exclude such an input.
function DoIt(){
var sht = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var Rng = sht.getDataRange().getValues();
Rng.forEach(function (row,index) {
if (row[0] == "") { // row[0] is the same as Column A. row[1] = B
Rng.length = index;
}
});
var newRange = sht.getRange(Rng.length,1);
Logger.log(newRange.getA1Notation());
}
For example, in the below image, the lastRow
should be row 11
as there is a value in cell D11
and lastColumn
should be column F
as there is value in cell F3
. So [row: 11, col: 6] should be the immediate answer.
Is there an efficient and quicker way to find the true lastrow and lastcolumn of a sheet?
flush()
before checking withgetLastRow()
? – Oleg Valter