Skip to content

Instantly share code, notes, and snippets.

@palumbo
Created September 14, 2022 02:30
Show Gist options
  • Save palumbo/f80b8d98e5a3595f5b40efd3662ae9f3 to your computer and use it in GitHub Desktop.
Save palumbo/f80b8d98e5a3595f5b40efd3662ae9f3 to your computer and use it in GitHub Desktop.
Sorts payroll election order based on amount and percentage
function myFunction() {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let lastRow = sheet.getLastRow();
for (var i = 1; i < lastRow; i++) {
let check1 = sheet.getRange(i+7,2).getValue(); // GETS FIRST VALUE IN COLUMN B
let check2 = sheet.getRange(i+6,2).getValue(); // GETS SECOND VALUE
if (check1 == check2) {
let amount = sheet.getRange(i+7,33).getValue();
let percent = sheet.getRange(i+7,34).getValue();
if (amount != "" || percent != "") {
Logger.log(i+7 + " | " + amount); Logger.log(i+7 + " | " + percent);
let rowToMove = sheet.getRange(i+7,1,1,35);
rowToMove.setBackground('red');
sheet.moveRows(rowToMove,i+6);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment