Home > Software design >  Showing Invalid Argument
Showing Invalid Argument

Time:12-01

I'm trying to create a form with a submit button, but the code i created, keeps returning an error.

I tried this code: `

function SubmitCard() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var crdSht = spreadsheet.getSheetByName("Cards");

  var data
  [[ crdSht.getRange("A2").getValue(),
  crdSht.getRange("B2").getValue(),
  crdSht.getRange("C2").getValue(),
  crdSht.getRange("D2").getValue(),
  crdSht.getRange("E2").getValue(),
  crdSht.getRange("F2").getValue() ]];

      crdSht.getRange(crdSht.getLastRow() 1,1,1,6).setValues(data);
}

` I was expecting the code to insert my data values in the row under the last row with data.

CodePudding user response:

Use Sheet.appendRow(), like this:

function SubmitCard() {
  const ss = SpreadsheetApp.getActive();
  const crdSht = ss.getSheetByName('Cards');
  const data = crdSht.getRange('A2:F2').getValues().flat();
  crdSht.appendRow(data);
}

CodePudding user response:

This works for me:

function SubmitCard() {
  var ss = SpreadsheetApp.getActive();
  var crdSht = ss.getSheetByName("Sheet0");
  var data = [[crdSht.getRange("A2").getValue(), crdSht.getRange("B2").getValue(), crdSht.getRange("C2").getValue(), crdSht.getRange("D2").getValue(), crdSht.getRange("E2").getValue(), crdSht.getRange("F2").getValue()]];
  crdSht.getRange(crdSht.getLastRow()   1, 1, 1, 6).setValues(data);
}
  • Related