Running Multiple Scripts in Google Sheets help please

34 views
Skip to first unread message

Kevin Firth

unread,
Apr 13, 2026, 7:39:06 AM (12 days ago) Apr 13
to Google Apps Script Community
Hi all, 
I need some help please. I am a complete newbie, just googling answers to try and achieve what we need.
I am trying to run multiple scripts on a single Google sheet so that each table will auto-update and move the highest players to the top of each group using the PTS column to get a leaderboard in each table automatically when figures are entered.

The script I found and works in Group A, I also need to work in all groups.


Thanks in advance

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("NSC");
var range = sheet.getRange("A8:E13");

function onEdit(e)  {
  range.sort([{column: 5, ascending: false}]);
}
___________________________________
So when I copy & paste the above eight times and alter the Get Range and Column, only one seems to work at any time.

I have read somewhere that you can only have one sheet named, for example, NSC but still don't understand how to fix it.

If someone could kindly copy the above code twice and fix it so both work at the same time maybe i can copy and paste it 8 times and find out what needs changing ?

Thankyou

Hope all that makes sense

Laurie Nason

unread,
Apr 13, 2026, 8:02:04 AM (12 days ago) Apr 13
to google-apps-sc...@googlegroups.com
Hi Kevin,

I have a few questions before providing a full solution.

Where are you entering the figures to change the ranking? Are they within the table you want to sort, or are they calculated elsewhere and pulled into the table?

If the data is entered directly into the table, you will need to adjust your script. Currently, the onEdit function will only recognize the first range defined. To sort multiple ranges, you must move the range definitions inside the function like this:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("NSC");

function onEdit(e) {
var range1 = sheet.getRange("A8:E13");
range1.sort([{column: 5, ascending: false}]);

var range2 = sheet.getRange("[Range 2]");
range2.sort([{column: 5, ascending: false}]);

var range3 = sheet.getRange("[Range 3]");
range3.sort([{column: 5, ascending: false}]);
// Repeat for additional ranges
}

Alternatively, I recommend keeping your data entry and results dashboard separate. This allows you to maintain a clean display while hiding the raw data. If you are open to displaying the results on a different tab, you could use the QUERY function to pull and sort your data automatically without needing a script.

Please let me know if you would like to walk through this second option.

Best regards,

Laurie Nason

Laurie

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/6696fd21-a151-4757-bfb6-47df8aa904ben%40googlegroups.com.

Kevin Firth

unread,
Apr 13, 2026, 12:12:38 PM (12 days ago) Apr 13
to Google Apps Script Community
Hi Laurie,

Firstly, many thanks for the response. I won't lie, I was clutching at hopes someone would help.

I have a Google Sheet page which I created, and the plan is to enter the points into the points columns, so Table A would be column E, and Table B would be column K, just using a few cells, not the whole column.

I am happy to have any working way that is best for what I need.

Thank so much again

KLev

Reply all
Reply to author
Forward
0 new messages