Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda