0

I am learning the Google app script.

I want to get data from one column (B) but the range is not specific it depends on the data.

I have this script but I do not know or understand how to get the range.

// get range of data by coordinates 
function getDataByRange() {
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getSheetByName('sheet');

   var data = sheet.getRange(...).getValue();

   Logger.log(data);
}

closed as unclear what you're asking by Rubén, serenesat, jonsca Feb 12 at 23:35

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • The question is unclear as it doesn't specify how the range depends on the data. Please edit the question to clarify this. – Rubén Feb 10 at 4:39
0

Hmm, this question does lack detail but the core is that you don't know how "getRange" works.

That's fine; it works in three broad ways:

  1. getRange(row, column) gives you a range of once cell and thus once value
  2. getRange(row, column, numRows) gives you range of how many cell you parameterize
  3. getRange(row, column, numRows, numColumns) gives you range of based on the start and end points.

For all of these, the "index" or reference (row,column) starts at 1.

You can also feed it a1Notation like Sheet!B1:B4 but I try to avoid that in Scripting.

In your scenario, say you wanted the entire column B to be stored in "data":

// get range of data by coordinates 
function getDataByRange() {
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getSheetByName('sheet');

   var data = sheet.getRange(1,2,sheet.getLastRow()).getValues();

   Logger.log(data);
}
  • sheet.getLastRow() gets you the last row in the sheet with data
  • getValues returns more than one value to the Object.

Have a look below for more info: - https://developers.google.com/apps-script/reference/spreadsheet/sheet#getRange(Integer,Integer) - https://developers.google.com/apps-script/reference/spreadsheet/sheet#getRange(Integer,Integer)

Not the answer you're looking for? Browse other questions tagged or ask your own question.