Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

287
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda