AnswerBun.com

How do I add information to a row with already containing some cells?

Stack Overflow Asked by aWeakProgrammer on January 5, 2022

I am using appendRow() to insert values in Google Sheet, and even if some fields are empty, it adds the values to the next line if any cell contains content.

Example: Cell C1 has a Sum formula, =SUM(A1,B1) When I insert a row with appendRow(), the values are added to A2 and B2 instead of A1 and B1, due to the content of C1.

Is there any way to solve this?

function showUserForm() {

  var template = HtmlService.createTemplateFromFile("userForm");

  var html = template.evaluate();

  html.setTitle("Form");

  SpreadsheetApp.getUi().showSidebar(html);

}

function appendData(data){

  var ws= SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Records");
  ws.appendRow([data.depo,data.phone,data.game]);

}

function errorMsg(){

  Browser.msgBox("Name & Phone Required");

}

One Answer

Try this:

function appendData(data){
  var sh=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Records");
  var rg=sh.getRange(sh.getLastRow(),1);
  rg.setValue(data.depo);//column A
  rg.offset(0,1).setValue(data.phone);//column B
  rg.offset(0,3).setValue(data.game);//column D
}

or

function appendData(data){
  var sh=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Records");
  var rg=sh.getRange(sh.getLastRow(),1,1,4);
  var vA=rg.getValues();
  vA[0][0]=data.depo;
  vA[0][1]=data.phone;
  vA[0][3]=data.game;
  rg.setValues(vA);
}

Answered by Cooper on January 5, 2022

Add your own answers!

Related Questions

“Live” data capable alternative for Google Earth KML

1  Asked on February 15, 2021 by christoph1197

   

React component dispatching generic payload

1  Asked on February 14, 2021 by andyroo

   

CSS animted gradient

1  Asked on February 14, 2021

     

Running a value through an array of functions

2  Asked on February 14, 2021 by lars-holdaas

   

How to revert back to python 2.7?

1  Asked on February 14, 2021 by nikhil-shrivastava

         

Using same name for attribute and getter

1  Asked on February 13, 2021 by janpeterka

     

What is the purpose to use className beside functionName using colon(:)

1  Asked on February 13, 2021 by mahedi-hasan-durjoy

 

Python: access a variable in a module from another file

2  Asked on February 13, 2021 by yeroduk

 

How to get elements of a sublist in Java

5  Asked on February 13, 2021 by alvira

     

`SyntaxError` in if-else one-liner

2  Asked on February 13, 2021 by evgeniy-golovin

         

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP