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");
}
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
1 Asked on February 15, 2021 by christoph1197
1 Asked on February 14, 2021 by andyroo
2 Asked on February 14, 2021 by hank
2 Asked on February 14, 2021 by lars-holdaas
1 Asked on February 14, 2021 by grango
c exception memory management new operator segmentation fault
1 Asked on February 14, 2021 by ajay-kumar
1 Asked on February 14, 2021 by andrew-vo
15 Asked on February 14, 2021 by david-essien
1 Asked on February 14, 2021 by nikhil-shrivastava
0 Asked on February 13, 2021 by elighne
1 Asked on February 13, 2021 by usef-juan
1 Asked on February 13, 2021 by janpeterka
1 Asked on February 13, 2021 by mahedi-hasan-durjoy
1 Asked on February 13, 2021 by bmalbusca
2 Asked on February 13, 2021 by yeroduk
0 Asked on February 13, 2021 by alexw-h-b
5 Asked on February 13, 2021 by alvira
2 Asked on February 13, 2021 by evgeniy-golovin
2 Asked on February 13, 2021 by lv98
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP