Script to fetch “range to sort” from google sheets not working (used to work)

I have data rows in multiple sections. I keep track of the start and end rows of each section in my google spreadsheet and they change dynamically as rows are inserted or deleted. I used App Script to fetch the current section X#:Y# from the spreadsheet and then run a script to sort it. This used to work perfectly, however, I recently did something that bricked it – and I cannot tell why…

Here’s an excerpt of the code:

function onEdit(){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var editedCell = sheet.getActiveCell();
  var columnToSortBy = 5;
  var tableRange = [];
  tableRange[0] = sheet.getRange(2,32).getValue(); //A6:K17
  tableRange[1] = sheet.getRange(3,32).getValue(); //A59:K62
  var range0 = sheet.getRange(tableRange[0]);
  var range1 = sheet.getRange(tableRange[1]);

if(editedCell.getColumn() == columnToSortBy){   


    range0.sort( { column : columnToSortBy } )
    range1.sort( { column : columnToSortBy } )

}
}

undefined variable?!
*Note: I copied the script from another StackOverflow post. It has served me well for nearly 2 months.

I tried looking at the debugger and my variables all appear as undefined. I tried manually replacing tableRange[0] with (for example) “A2:K10” and the script works fine. But as soon as I try the old way it stops working… I’m thinking this is something to do with JS as I’m totally ignorant of the language. Could you please help me?