Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
Return the sheet name when using TextFinder on Google sheets App script

I am searching for a word in a spreadsheet using TextFinder on Google sheets Script.

I would like to have as an output the name of the sheet where the text was found.

Usually they'll only be 1 of this keyword per spreadsheet and for sure only once per sheet.

If found more than 1 in spreadsheet would be nice to have all sheet names returned.

Code:

function TestCMNDH() {
  var source = SpreadsheetApp.openById('SheetID');
  var found = source.createTextFinder('Wordtosearch').matchCase(false).findAll();
  Logger.log(found)
};

Current output: [Range]

Any help would be greatly appreciated! Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could do something like this to get a unique list name of the spreadsheets where the text was found:

function myFunction() {
  var source = SpreadsheetApp.openById('SheetID');
  var foundRange = source.createTextFinder('Wordtosearch').matchCase(false).findAll();

  var sheetNames = foundRange.map(range => range.getSheet().getName());
  var uniqSheetNames = [...new Set(sheetNames)];

  uniqSheetNames.forEach(sheetName => Logger.log(sheetName));
}

What you get as a result of the findAll function is an array of Range.

You can get the Sheet that sheet belongs to using getSheet(), and you can get the name of that sheet using getName()

So I map that array of Range into an array of sheet names:

var sheetNames = foundRange.map(range => range.getSheet().getName());

The following line remove any possible duplicate, and then just log the names in the last line

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!