Get all selected cells in google script

  var range = '';
  var sel = SpreadsheetApp.getActive().getSelection().getActiveRangeList().getRanges();
  for(var i = 0; i < sel.length; i++){
    range += sel[i].getA1Notation() + ', ';
  }
  Logger.log(range);

Logs: [18-06-21 22:18:16:866 EEST] B1, B3,


Apps Script currently does not provide support for handling disjoint ranges within Range objects. What will happen is that the last selected sub-range will be returned by calls of getActiveRange(), etc. It is filed here as issue 4069. You may want to 'star' it.