user6842951
user6842951

Reputation: 1

when provided a value, looking to have the row number of the cell where that value resides

Please take a look at the following googleapps script code. the spreadsheet it references has 4 values in it. in a2 is the value "Two". I want that when I run this code, i receive an email with "2" in the subject line. I seem to keep on receiving a "4". Any ideas?

function rowofspecificvalue(){
var sheet = SpreadsheetApp.openById("1rMUrZFie94RLFDKaWVBPsQ-jebL8wNA6qsZWivMBDTk").getActiveSheet();
var data = sheet.getRange("a1:a4").getValues();
for(var i = 0; i<data.length;i++){
if(data[i][1] == "Two"){ 
 Logger.log((i+1))
  return i+1;
  }
 } MailApp.sendEmail ("[email protected]", i, "");
}

Thanks!

Upvotes: 0

Views: 27

Answers (1)

Viktor Gnat
Viktor Gnat

Reputation: 11

Write

MailApp.sendEmail("[email protected]", i-2, "")

and you will "2" have in subject. Second argument of MailApp.sendEmail() function set up subject of email.

Upvotes: 1

Related Questions