Building up on top of the other answers to provide you with a comprehensive collection of functions.
getCellRangeByColumnName
function getCellRangeByColumnName(sheet, columnName, row) {
let data = sheet.getDataRange().getValues();
let column = data[0].indexOf(columnName);
if (column != -1) {
return sheet.getRange(row, column + 1, 1, 1);
}
}
getCellValueByColumnName
function getCellValueByColumnName(sheet, columnName, row) {
let cell = getCellRangeByColumnName(sheet, columnName, row);
if (cell != null) {
return cell.getValue();
}
}
getColumnRangeByName
function getColumnRangeByName(sheet, columnName) {
let data = sheet.getRange("A1:1").getValues();
let column = data[0].indexOf(columnName);
if (column != -1) {
return sheet.getRange(2, column + 1, sheet.getMaxRows());
}
}
getColumnValuesByName
function getColumnValuesByName(sheet, columnName) {
let column = getColumnRangeByName(sheet, columnName);
if (column != null) {
return column.getValues();
}
}