How to automatically sort Google Form responses
I use Google Forms a lot and I love the product. However, one frustrating thing is that every time the form receives a new response, I have to scroll down to the bottom of the form's response spreadsheet to see it. I would much rather have new responses at the top of the spreadsheet so I immediately see them when I open the spreadsheet.
In this tutorial, I'll show you how to automatically sort your Google Form's responses so you'll always see the most recent ones at the top. This has saved me so much time over the past few months! If your form receives a lot of responses, it can be pretty painful to scroll through and find the new responses each time so I hope you find this tutorial helpful.
Step 1 — Open the spreadsheet that is collecting the responses from your form
For this tutorial, I created a test form with just two questions. The form asks users to enter their name and favorite color.
I submitted 10 responses one after another and they were saved to the form's spreadsheet in the order that I submitted them. What we want to achieve in this tutorial is for these responses to be sorted such that the most recent responses are at the top of the spreadsheet.
Step 2 — Create a Google Apps Script to sort the sheet by the Timestamp column in descending order
Open the script editor by selecting Extensions —> Apps Script from the menu. In the script editor, replace the myFunction function with the code below and save the script by selecting File —> Save from the editor's menu (or by pressing CTRL + S
on your keyboard).
Replace the code in the script editor with the code below.
/** @OnlyCurrentDoc */
function sortResponses() {
var sheet = SpreadsheetApp.getActive().getSheetByName("Form Responses 1");
sheet.sort(1, false);
}
Save your script and try running it. Once the script finishes running, your spreadsheet should be sorted such that the most recent responses are at the top.
Note:
When you run your script, you might be asked to authorize it and grant it permissions so it can access your spreadsheet.
How does the sortResponses() function work?/** @OnlyCurrentDoc */
function sortResponses() {
var sheet = SpreadsheetApp.getActive().getSheetByName("Form Responses 1");
sheet.sort(1, false);
}
/** @OnlyCurrentDoc */
function sortResponses() {
var sheet = SpreadsheetApp.getActive().getSheetByName("Form Responses 1");
sheet.sort(1, false);
}
The script is very simple.
First, it gets the sheet containing your form's responses. The script assumes that this sheet is called "Form Responses 1", which is the default name generated by Google Forms. If you change this name in your spreadsheet, make sure you also update the script.
Next, it sorts the sheet by the first column in descending order. The script assumes that the first column contains the timestamps of the responses. The second parameter of the sort() function specifies the sort order. Setting it to
false
will sort in descending order (if you set it totrue
, your spreadsheet will be sorted by timestamp in ascending order).
Note:
The code /** @OnlyCurrentDoc */
tells your script that it only needs permission to access the spreadsheet containing your form's responses.
While this is not strictly necessary, it is a good security and privacy practice to limit scripts so that they can only access the data they absolutely need.
Step 3 — Create a Form Submit trigger to automatically run the sortResponses() function whenever your form is submitted
Now that you have successfully tested your script, the next step is to have it run automatically whenever your form is submitted. To do this, you'll need to set up a Form submit trigger. A trigger is a feature in Google Apps Script that enables you to automate tasks and workflows.
Once you set it up, the trigger will automatically run the sortResponses()
function whenever your form is submitted. Therefore, your sheet will already be sorted with the most recent response at the top when you open it the next time.
Step 3.1 — Open the triggers page by clicking on the clock iconStep 3.2 — Click Add trigger to create a new Trigger Step 3.3 — Configure your trigger and save it
Step 3.3 — Configure your trigger and save it
Choose sortResponses
as the function to run and choose "On form submit" as the event type. Click save to create the trigger.
Note:
When you click Save, you might be asked to authorize your script once again to grant it additional permissions to View and manage forms that the script has been installed in.
The trigger will be created once you authorize your script by clicking Allow.
Your trigger is now created and it should be listed on your script's triggers page.
Step 3.4 — Test your trigger by submitting a new form response
When you submit a new response, the trigger will automatically run the sortResponses()
function and your response will move to the top of your sheet.
If that did not work, try running your function manually to confirm that it works correctly (you can drag a few rows around so the sorting becomes out of order to test if running the sortResponses()
function puts the rows back in the correct sort order).
Step 4 — (optional) Turn on email notifications so you're notified when your form is submitted
In addition to automatically sorting form responses, I usually also turn on email notifications in my forms so I'm notified whenever my form is submitted.
To turn notifications on in your form, select the three dots menu in the Responses tab of your form.
Then select "Get email notifications for new responses" from the menu.
Now, you'll get email notifications whenever your form is submitted and when you open the form's spreadsheet, the most recent response will be at the top!
Conclusion
In this tutorial you learned how to automatically sort your Google Form's responses so you don't have to scroll to the bottom of your form's spreadsheet to see the most recent responses.
To set this up, you need to:
First, create an Apps Script to sort the spreadsheet containing responses by timestamp in decreasing order.
Then, set up a Form submit trigger to run your script automatically whenever your form is submitted.
You also learned how to set up email notifications so you're notified whenever your form is submitted. These two features are complementary and together they have saved me a ton of time and I hope you'll save a lot of time too.
Thanks for reading!