Skip to content

Instantly share code, notes, and snippets.

@JustinByrne
Last active May 7, 2020 08:57
Show Gist options
  • Save JustinByrne/c265ddd4a3e4cf90a2a1be6b822abfa3 to your computer and use it in GitHub Desktop.
Save JustinByrne/c265ddd4a3e4cf90a2a1be6b822abfa3 to your computer and use it in GitHub Desktop.
// get column by the content in it - first row only
function getColByName(columnName) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange(1, 1, 1, sheet.getLastColumn());
var values = range.getValues();
for (var row in values) {
for (var col in values[row]) {
if (values[row][col] == columnName) {
var num = Number(col) + 1;
return num.toFixed();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment