I am looking for a way to check if a cell contains text in Google Apps Script and Google Sheets.
var cell = "Joe, Bob, Tim, John"
//I would want this to execute
if(cell contains "Tim") {
//code
}
I am looking for a way to check if a cell contains text in Google Apps Script and Google Sheets.
var cell = "Joe, Bob, Tim, John"
//I would want this to execute
if(cell contains "Tim") {
//code
}
Recently, a
TextFinder
class was has been added to theSpreadsheetApp
service that allows you to do this on a liveRange
(orSheet
or even aSpreadsheet
itself). See documentation for more details. Simply set the finder on a context with acreateTextFinder()
with the text you want to find as an argument. Calling afindNext()
method on the resultingTextFinder
instance will either return theRange
it was called on ornull
if nothing was found. For example: