Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
script help, i am new to coding

hello i am new to coding , this is a google sheet app script problem that i have, so, i have 2 sheet and i want to sort in order both of them, sort different column , ive succeded in making the code work for both of them but my issue is that it will only work for 1 of them, seem like the function im creating only work for the 1st function ive enter, the second below dont work, but will work individualy, what im trying to do is to create 1 function that work for both of my sheet, anyone know ?

SHEET_NAME = "The Convenant { Member Roster )";
SORT_DATA_RANGE = "B5:J1187";
SORT_ORDER = [
{column: 5, ascending: true},  // 5 = column number, sorting by descending order
{column: 4, ascending: true}, // 1 = column number, sort by ascending order
];

function onEdit(e){
  multiSortColumns();
}
function multiSortColumns(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName(SHEET_NAME);
  var range = sheet.getRange(SORT_DATA_RANGE);
  range.sort(SORT_ORDER);
  ss.toast('Sort complete.');
}
SHEET_NAME = "The Convenant ( War Roster )";
SORT_DATA_RANGE = "B5:I1086";
SORT_ORDER = [
{column: 3, ascending: true},  // 3 = column number, sorting by descending order
{column: 2, ascending: true}, // 1 = column number, sort by ascending order
];

function onEdit(e){
  multiSortColumns();
}
function multiSortColumns(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName(SHEET_NAME);
  var range = sheet.getRange(SORT_DATA_RANGE);
  range.sort(SORT_ORDER);
  ss.toast('Sort complete.');
}

enter image description here

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can't duplicate twice the same function, for instance onEdit and multisortcolumns. Try

function onEdit(e){
  multiSortColumns();
}
function multiSortColumns(){
SHEET_NAME = "The Convenant { Member Roster )";
SORT_DATA_RANGE = "B5:J1187";
SORT_ORDER = [
{column: 5, ascending: true},  // 5 = column number, sorting by descending order
{column: 4, ascending: true}, // 1 = column number, sort by ascending order
];
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName(SHEET_NAME);
  var range = sheet.getRange(SORT_DATA_RANGE);
  range.sort(SORT_ORDER);
  ss.toast('Sort complete.');

SHEET_NAME = "The Convenant ( War Roster )";
SORT_DATA_RANGE = "B5:I1086";
SORT_ORDER = [
{column: 3, ascending: true},  // 3 = column number, sorting by descending order
{column: 2, ascending: true}, // 1 = column number, sort by ascending order
];
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName(SHEET_NAME);
  var range = sheet.getRange(SORT_DATA_RANGE);
  range.sort(SORT_ORDER);
  ss.toast('Sort complete.');
}

but may be yoy can test on which tab the onedit function is relative

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!