i have a list of urls in column A and i want to loop this column A and set the status code for each url to column B. I tried this code but i keep getting Range not foun
There are probably better (and more elegant) ways to do it, but at least this seems to work:
function getStatus() {
var queryString = Math.random();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var dataRange = sheet.getRange(2, 1, lastRow -1, lastColumn);
var data = dataRange.getValues();
var row = 0;
var len = data.length;
for (row; row < len; row++) {
if (data[row] != '') {
var cellFunction1 = '=HTTPResponse("' + data[row][0] + '?' + queryString + '")';
// change the following line, last number for another column
var cell = sheet.getRange(row+2, 2);
cell.setValue(cellFunction1);
}
}
}
function HTTPResponse( uri )
{
var response_code ;
try {
response_code = UrlFetchApp .fetch( uri ) .getResponseCode() .toString() ;
}
catch( error ) {
response_code = error .toString() .match( / returned code (\d\d\d)\./ )[1] ;
}
finally {
return response_code ;
}
}
Maybe you can go from here and improve it. screenshot spreadsheet columns