Skip to content

Instantly share code, notes, and snippets.

@bahostetterlewis
Last active August 29, 2015 14:16
Show Gist options
  • Save bahostetterlewis/2f52190e7efe6a83cda6 to your computer and use it in GitHub Desktop.
Save bahostetterlewis/2f52190e7efe6a83cda6 to your computer and use it in GitHub Desktop.
Recipe for Using Formulas in Google Forms
// global
var ss = SpreadsheetApp.getActive();
function addRow() {
var sh = ss.getActiveSheet(), lRow = sh.getLastRow();
var lCol = sh.getLastColumn(), range = sh.getRange(lRow,lCol);
range.setValue("=SOME_FORMULA")
}

This is pretty simple to setup - particularly useful when combining Google Forms with Zapier.

Problem

It is impossible to create forumlas in a Google Form

Solution

If we create a google script that is triggered on the form submition we can modify extra cells at the creation.

Setup

  • Create a new Google Form
  • Link it to a spreadsheet
  • Navigate to the spreadsheet
  • Setup the script
    • Tools->Script Editor
  • Paste the Script into the editor and modify as necessary
    • Don't forget to save!
  • Look for the clock icon (this sets up triggers)
    • add a new trigger
      • Run -> addRow
      • Events
        • From spreadsheet
        • On form submit

You may need to delete extra rows (the form will add them as needed anyway)

Now whenever a person submits a new form, the formula will be added to the desired cell automatically

The only part that would be harder to change is the line

var sh=ss.getActiveSheet(), lRow = sh.getLastRow()

That part should give you the row number that was just created by the form (which is the one you obviously want to modify)

References

Basic code from webapps.stackexchange.com User Jacob Jan Tuinstra

On this post

Note this doesn't show setting up the triggers for forms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment