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

208
Views
Returning a Random Cell Value

I'm trying to use google scripts to select a random row from google sheets and return some of the cell values in those rows to email to me.

Here's what I have so far:

function sendEmails() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];

  var numRows = sheet.getLastRow();
  var randomNumber = Math.random() * numRows; 

  var bodyTitle = SpreadsheetApp.getActiveSpreadsheet().getRange(3, randomNumber).getValue();
  var bodyHighlight = getActiveSpreadsheet().getRange(D + randomNumber).getValue();
  var bodyLink = getActiveSpreadsheet().getRange(B + randomNumber).getValue();

var body = bodyTitle + " | " + bodyLink + " | " + bodyHighlight; 

  var recipient = "x@gmail.com";
  var subject = "resurfaced highlights";
  var body = "test";
  MailApp.sendEmail(recipient, subject, body);
}

I'm currently getting an error that says

Error
Exception: The parameters (String,number) don't match the method signature for SpreadsheetApp.Spreadsheet.getRange. sendEmails @ send emails.gs:9

Does anyone know how I'd go about formatting this properly so as to avoid this error?

about 4 years ago · Santiago Trujillo
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!