Home > Software engineering >  Running App Script with output on a different Sheet
Running App Script with output on a different Sheet

Time:05-26

I have found a script that pulls data from a cell and adds a row to the bottom of the Google Sheet, but I want to be able to have the output on a separate sheet called "Data". Here is the script:

function recordValue() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Channels");
var date = new Date();
var value =sheet.getRange("B9").getValue();
sheet.appendRow([date,value])
}

I know I need to change the sheet.appendRow but I don't know what I need to get it to another sheet, say in cell A2.

CodePudding user response:

You must declare the second sheet.

function recordValue() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Channels");
  var dataSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data");
  var date = new Date();
  var value = sheet.getRange("B9").getValue();
  dataSheet.appendRow([date,value])
}

See:

CodePudding user response:

Outputting on a different sheet

function recordValue() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Channels");
  const dsh = ss.getSheetByName("Data")
  dsh.getRange(dsh.getLastRow()   1, 1, 1,2),setValues([[new Date(),sh.getRange("B9").getValue()]]);
}
  • Related