How to check if the value is exist in google spreadsheet or not using apps script
I want to check if the Sam exist in the entire spreadsheet or not using apps s
You can define a textFinder and run it over your data range.
function findSam() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var range = sheet.getDataRange();
var textFinder = range.createTextFinder('Sam');
var locations = [];
var occurrences = textFinder.findAll().map(x => x.getA1Notation());
if (occurrences == []) {
// do something if "Sam" not in sheet
}
else {
// do stuff with each range:
}
}
This code will:
Range object that contains "Sam" to an array of rangesFrom here you can do what you wish with the ranges. If "Sam" is not in the sheet then occurrences will be an empty array and you can do here what you wish.
I hope this is helpful to you!