Skip to content

Instantly share code, notes, and snippets.

@Dials-Mavis
Dials-Mavis / Sort Google Sheet by two columns, 'Platform' and 'Team'.js
Last active March 22, 2023 04:52
Gogle App Script: Sort all rows with data (excluding header row), ascending, by two columns, taking two column header names in case the columns are rearranged.
// This function gets column numbers by the header name
function getColumnNrByName(sheet, name) {
var range = sheet.getRange(1, 1, 1, sheet.getMaxColumns());
var values = range.getValues();
for (var row in values) {
for (var col in values[row]) {
if (values[row][col] == name) {
return parseInt(col);
}