Return Row Data from Spreadsheet having specified string without looping through all Rows

Viewed 1102

I have a task at hand wherein I need to return the entire Row Data containing a user-defined string.

One way of achieving it is looping through all the rows, but this works only when you know in which column to search, as shown using the code given below.

var sheetData = SpreadsheetApp.getActiveSpreadsheet().getDataRange().getValues();
var searchString = "testSearch";

for(var i=0;i<sheetData.getLastRow();i++)
{
  //assuming we know that the search string is going to be in Column 2
  if(sheetData[i][1].search(searchString)!=-1)
  {
    var rowData = sheetData[i];
    return rowData;
  }
}

So my question is, is there any way in which we can achieve this, without having to loop through all rows one by one?

To make the problem statement more clear, I wish to achieve something like the 'Find' feature as demonstrated in the image below:

enter image description here

This would make it very easy to skim through huge data spread across multiple sheets/spreadsheets.

Note: I am searching for a solution to this using Google Apps Script.

1 Answers
Related