Error TypeError: Cannot read properties of null (reading 'sort') sortResponses @ Code.gs:4

1,772 views
Skip to first unread message

Ka Hiang Cheok

unread,
Dec 27, 2022, 8:00:23 AM12/27/22
to Google Apps Script Community

Hi... I'm a beginner.

My AppsScript..... (sheet is from Google Form Response)

/** @OnlyCurrentDoc */
function sortResponses() {
  var sheet = SpreadsheetApp.getActive().getSheetByName("RIR1(Responses)");
  sheet.sort(2, false);
  sheet.sort(5, false);
}

Having run it, I've got

Error
TypeError: Cannot read properties of null (reading 'sort')
sortResponses
@ Code.gs:4
 
I'd be glad if anyone can help..... Thank you.

Mateusz Krajewski

unread,
Dec 27, 2022, 10:17:11 AM12/27/22
to Google Apps Script Community
Hi there,

I think that maybe you should define the range of cells/values you wanna sort and then sort that range. Currently you only specified the sheet your script should work on. I can see that you also specify the column number you wanna use in your sort(). Try with getRange() for example.
Reply all
Reply to author
Forward
0 new messages