Google-sheets – How to automatically align incoming form responses in Google Sheets

google sheetsgoogle-formsgoogle-sheets-form-submissions

I like to have each of my form responses aligned in the center of their cells. However when I submit any new information through Google Forms, they are always automatically aligned to the left, and so I am forced to constantly go back and highlight all of these cells and click Format → Align → Center.

Is there someway I can have my form responses automatically aligned in the center after each new submission? Or do I always have to go back and align them myself later?

Best Answer

It looks like this issue is due to a bug in the new Google Sheets, but you can use this simple script as a workaround.

  • In your sheet, go to Tools > Script Editor. Erase the existing code in Code.gs and add this instead:

    function setCellAlign(range, alignment) {
       var ss = SpreadsheetApp.getActiveSpreadsheet();
       var sheet = ss.getSheets()[0];
       var cell = sheet.getRange(range);
       cell.setHorizontalAlignment(alignment);
     }
    function onFormSubmit() {
       setCellAlign("A1:F500", "center");
    }
    
  • In the second-to-last-line, change F500 to the expected bottom-right cell of your sheet. For example, if your rightmost column is G and you want to hold 1000 responses in your sheet, change the value to G1000 so the second-to-last line is setCellAlign("A1:G1000", "center");

  • Save the script project as "AutoAlign"

  • Within the Script Editor, go to Resources > Current project's triggers. Add a new trigger for onFormSubmit, From the spreadsheet, On form submit, and press "Save."

Your responses should now align automatically to the center. For whatever reason, this script fails to work 1% of the time, but if that happens the next form submission will fix the previous row.