Changing value of a cell based on another value in the same row on Google form submit

665 views Asked by At

I'm very new to Google Forms and Spread Sheets and what I wanna do is that I have an "Age" question in my form, and when the user submits the form I want it so that if the age is below 18, a cell gets the value "MINOR" and if it is 18 or above, it gets filled with "MAJOR".

Basically I want to dynamically add a value to this cell base on the value of "AGE".

What I'm doing right now:

function myfunction(e) {
  var age = Number(e.values[3]);
  var minmaj;
  if (age < 18){
    minmaj = "MINOR";
  } else {
    minmaj = "MAJOR";
  }
  SpreadsheetApp.getActiveSheet().getRange(e,14).setValue(minmaj);
}

Where e,14 is the cell of value minor/major.

2

There are 2 answers

0
Chris Hick On

This formula may work as you want if entered in row 2 of the column to the right of your Form response data:

=ARRAYFORMULA(IF(A2:A="",,IF(E2:E<18,"MINOR","MAJOR")))

It will automatically detect new submissions and populate the cell based on the value in column E

0
Mogsdad On

Yes, simple problem...

SpreadsheetApp.getActiveSheet().getRange(e,14).setValue(minmaj);
                                         ^

In that line, you're trying to use the event variable e as a row number. Should be something like this:

SpreadsheetApp.getActiveSheet().getRange(e.range.getRow(),14).setValue(minmaj);
                                         ^^^^^^^^^^^^^^^^