Skip to content

Instantly share code, notes, and snippets.

@rodrigomojeda
Created March 14, 2019 14:33
Show Gist options
  • Save rodrigomojeda/b798a2f287990f786e4d079058d5f5cd to your computer and use it in GitHub Desktop.
Save rodrigomojeda/b798a2f287990f786e4d079058d5f5cd to your computer and use it in GitHub Desktop.
Searches for a string in a Google Sheets sheet.
/* Searches for a string in a sheet*/
function searchString(stringToSearch,sheetName) {
var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var selection=sheet.getDataRange();
var columns=selection.getNumColumns();
var columnsnames = selection.getColumn()
var rows=selection.getNumRows();
for (var column=1; column < columns; column++) {
for (var row=1; row < rows; row++) {
var cell=selection.getCell(row,column);
if (cell.getValue() == stringToSearch ) {
return true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment