Skip to content

Instantly share code, notes, and snippets.

@mogsdad
Last active December 14, 2015 02:38
Show Gist options
  • Save mogsdad/5014758 to your computer and use it in GitHub Desktop.
Save mogsdad/5014758 to your computer and use it in GitHub Desktop.
With Google forms, responses are saved into a spreadsheet. You may want to remove some or all responses, but there's no form API that allows that. This gist contains a function that can remove some or all responses, starting with the first (oldest) one. This works with the legacy forms product (pre-February 2013). This was written in response to…
/**
* Delete form response rows. If no input parameter is provided, prompt user
* for the number of form response rows to remove. To remove all rows, input
* -1.
*
* Assumes that the form responses are in the active sheet, that there is one
* row of 'headers' followed by responses (starting in row 2).
*
* @param {number} thisMany (Optional) The number of rows to remove. If not
* specified, user will be prompted for input.
*/
function tidy(thisMany) {
if (tidy.arguments.length == 0) {
thisMany = Browser.inputBox("How many responses should be tidied? (-1 for all)");
}
var sheet = SpreadsheetApp.getActiveSheet();
if (thisMany == -1) {
thisMany = sheet.getDataRange().getNumRows() - 1;
}
if (thisMany == 0) {
// Nothing to do
return;
}
else {
// Delete thisMany rows, starting in row 2.
sheet.deleteRows(2, thisMany);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment