0
votes

I'm quite new to google sheet script and looking for some assistance. I am trying to make a google script that will erase cells in a response sheet after a user has submitted it. As this could be a form edit url, it may not necessarily be the last row.

So everytime a form is submitted / edited, columns AN:AQ are cleared.

Any help greatly appreciated


I'm adding the working script to OP's question for anyone who comes across this.

function onFormSubmit11(e) { 
   var range = e.range; 
   var ss = range.getSheet(); 
   var row = range.getRowIndex(); 

ss.getRange("AN"+row).clear(); 
ss.getRange("AO"+row).clear(); 
ss.getRange("AP"+row).clear() 
ss.getRange("AQ"+row).clear() 
} 
2
Are you adding the trigger on the destination spreadsheet or on the form? The structure of the event object is dependent on your choice.tehhowch

2 Answers

0
votes

The Spreadsheet trigger invoked by the Google Form contains the Range object. You can retrieve the sheet linked to the range as well the index of the row linked to the current form submission.

function formTrigger(e) {
  var range = e.range;
  var sheet = range.getSheet();
  var rowIndex = row.getRowIndex();
  sheet.getRange(rowIndex + 1, 1).setValue("Hello");
}
0
votes

You could try something as simple as an onFormSubmit running the script through your linked spreadsheet. The script below will clear AN:AQ every time a form is submitted which is 'alf of what I think you're asking for.

As for on edit, that's something I'm trying to figure out myself in my own question!

function onFormSubmit() {

var ss = SpreadsheetApp.getActiveSpreadsheet()
var sh = ss.getActiveSheet()

sh.getRange('AN1:AQ').clear();

}

Hi Again,

Try this below. As before, make sure your trigger is set on OnFormSubmit and it should work flawlessly. I've tested it myself, it only cleared the range between AN:AQ on row (wherever the form edits). If you want to delete different sections just replace the AN:AQ for whatever column(s) you wish to clear.

function onFormSubmit(e) {

var range = e.range;
var ss = range.getSheet();
var row = range.getRowIndex(); 

ss.getRange("AN:AQ"+row).clear();

}