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 }
thumbnail

NitroGAS Chrome Extension

Want to reference this code snippet right from your Google Apps Script Project? Check out our NitroGAS Chrome Extension. This tool will help you build your scripts faster than you could imagine. The tool itself and access to the code snippets are 100% FREE - Happy Coding!

Get the Extension