How to set cell value (range of cells) based on the result of another function?

Issue

I have a spreadsheet (Web) with urls in column E and empty cells in column F.
Function getTitle takes url from E and returns its Title.
But how can i write all Titles to column F near their urls? Please, help.

function myFunction() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var s=ss.getSheetByName('Web');
  var r=s.getRange("'Web'!E1:F");
  var rws=r.getValues();
  for(var i=0; i<rws.length; i++) {
    var url = rws[i][0];
    var title = getTitle(url);
    ???
  }
}

Solution

Try this:

function myFunction() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var s=ss.getSheetByName('Web');
  var r=s.getRange("'Web'!E1:F");
  var rws=r.getValues();
  for(var i=0; i<rws.length; i++) {
    var url = rws[i][0];
    rws[i][1] = getTitle(url);
  }
  r.setValues(rws);
}

Answered By – Yuri Khristich

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.