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

288
Views
Exception: Range not found. Trying to place multiple columns using an active cell. (however works when manually entered)

I'm trying to insert values into cells. Here is my code:

var values = [
              ["test1", "test2", "test3"]
             ];

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

var cellsToWriteTo = []
function testFunction() {
  var activeCell = sheet.getActiveCell();
  var firstRow = activeCell.getRow()
  var firstColumn = activeCell.getColumn()

  cellsToWriteTo = `["R${firstRow}C${firstColumn}:R${firstRow}C${firstColumn + 2}"]`
  console.log(cellsToWriteTo)

  var range = sheet.getRange(cellsToWriteTo)
  range.setValues(values);
}

This gives me the error:

Exception: Range not found

However if I copy and paste cellsToWriteTo from the console log and put it into getRange.. it works perfectly every time..

Things i have tried so far:

Thought it was to do with not fetching the spreadsheet correctly (getActiveSpreadsheet().getActiveSheet()).

Fixed how my values were organised (into arrays within arrays)

Googled the error message and looked at how to properly getRange/setRange in the documentation and in tutorials. Apparently you cannot set arbitrary cells if you are calling them from the excel sheet itself. This is my suspicion as to what is going wrong here. However how can this be the case if when I put in a simple string it functions fine. I am simply doing string interpolation here.

I know this is rudimentary stuff, any help would be appreciated.

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

0

Removing both brackets and quotation marks should make it work

Modification:

cellsToWriteTo = `R${firstRow}C${firstColumn}:R${firstRow}C${firstColumn + 2}`

Execution:

output

Output:

output2

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!