Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I convert this textFinder to only return the email it finds in a specific column?

I currently have a Spreadsheet table of employee details. The code below works fine as long as the email is unique (only one occurrence in the table’s column E). However, other user emails are also found in the supervisor/manager columns email, which results into the code below referencing that first email occurrence and thus messing up the userFullName output. What I wanted to do is to search only a specific column, column E, for the userEmail.

   var userEmail = Session.getActiveUser().getEmail();
   var url = '';
   var ss= SpreadsheetApp.openByUrl(url);
   var thisSheet = ss.getSheetByName("employeeList");
   var tf = thisSheet.getRange("A1:Z" + thisSheet.getLastRow()).createTextFinder(userEmail);
   var userFullName = tf.findNext().offset(0, -4, 1, thisSheet.getLastColumn()).getValues()[0][1];
   console.log(userFullName);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

From What I wanted to do is to search only a specific column, column E, for the userEmail., if you want to search a value of userEmail from only column "E", how about the following modification?

From:

var tf = thisSheet.getRange("A1:Z" + thisSheet.getLastRow()).createTextFinder(userEmail);

To:

var tf = thisSheet.getRange("E1:E" + thisSheet.getLastRow()).createTextFinder(userEmail);
  • The method of createTextFinder of Class Range can search the value from the range.

  • From your scriptm, it supposes that there is no header row. If you have a header row, please modify E1:E to E2:E.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading