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();




function appendData(data){

  var ws= SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Records");


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(;//column B
  rg.offset(0,3).setValue(;//column D


function appendData(data){
  var sh=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Records");
  var rg=sh.getRange(sh.getLastRow(),1,1,4);
  var vA=rg.getValues();

Answered by Cooper on January 5, 2022

Add your own answers!

Ask a Question

Get help from others!

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