Lookup The Matching Row Index Using a Search Term

This snippet is very helpful when you need to make updates to a specific row in a Google sheet and have an identifier that you can use to locate the correct row.

To utilize this function, you'll need the Sheet object, the column index that your identifiers are located in, and the search term (e.g. the identifier) you'll be using.

/** * Returns the column index of a specified value * * @param {Sheet} the Sheet Object you're looking for the value in * @param {number} the column number in which you expect to find the identifier * @param {text} the identifer you want to find within the sheet * @return {number} the index value of the row matching the lookupValue */ function findRowIndexByTerm(lookupSheet, columnIndex, lookupValue) { let values = lookupSheet.getDataRange().getValues() let index = values.findIndex(row => row[columnIndex] === lookupValue) return index + 1 }

NitroGAS Chrome Extension

Want this snippet handy inside the Apps Script editor? NitroGAS gives you free themes and snippets — plus optional Co-Pilot when you want a boost (1-week, 1-month, or yearly passes — no subscription). Happy Coding!

Get the Extension