You want to return the "used" range. As @TheMaster has pointed out, there is no method that will do this. However, it is possible to get the range by looping through rows and columns.
Try this script:
function usedRange() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getSheetByName("so_79510837")
var range = sheet.getDataRange()
var values = range.getValues()
var numRows = values.length
var numCols = values[0].length
// Logger.log("DEBUG: number of Rows = "+numRows+" and number of Columns = "+numCols)
// loop though rows to find the first row with data
for (var r=0;r<values.length;r++){
if (values[r].filter(String) >1){
var rowNumber = r+1
Logger.log("DEBUG: row number "+rowNumber+" is the first row to contain data")
break
}
}
// loop though columns to find the first column with data
for (var c=0;c<values[0].length;c++){
// get each column as a 1D array
var columnData = values.map(function(e){return e[c];});
if (columnData.filter(String) >1){
var colNumber = c+1
Logger.log("DEBUG: Column number "+colNumber+" is the first column to contain data")
break
}
}
// Logger.log("DEBUG: last row = "+sheet.getLastRow()+", last column = "+sheet.getLastColumn())
var usedRange = sheet.getRange(rowNumber,colNumber,sheet.getLastRow()-rowNumber+1,sheet.getLastColumn()-colNumber+1)
Logger.log("DEBUG: the used range = "+usedRange.getA1Notation())
}
Sample output
DEBUG: the used range = D6:J18
Sample data
| A |
B |
C |
D |
E |
F |
G |
H |
I |
J |
K |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|