Reputation: 393
I have an existing Google Sheet which I would like to create a form for so users can input data more easily.
The form would have three questions and I would like them to go into their corresponding columns on the existing spreadsheet.
Question 1 would go into Column 1, Question 2 would go into Column 3 on the same row and Question 3 would go into Column 5 on the same row.
Does anyone know how I can do this or an Apps script for this please?
Upvotes: 3
Views: 9347
Reputation: 26796
On each form submitting the responses will automatically go into your spreadsheet - most likely into a new sheet created automatically.
onFormSubmit
triggeronFormSubmit
retrieve the newest response with the event object namedValues
Sample:
function myFunction(e) {
var mySheet = SpreadsheetApp.getActive().getSheetByName("PASTE HERE THE SHEET NAME");
var freeRow = (mySheet.getLastRow()+1);
var column1 = 1;
var column3 = 3;
var column5 = 5;
// replace the following question titles by your real question titles
mySheet.getRange(freeRow, column1).setValue(e.namedValues["What is your name?"]);
mySheet.getRange(freeRow, column3).setValue(e.namedValues["How old are you?"]);
mySheet.getRange(freeRow, column5).setValue(e.namedValues["Do you like Apps Script?"]);
}
Upvotes: 6