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

314
Visualizações
In Google App Script, Range.getValue() gives different results on two cells with the exact same formula

I'm writing a script for my Google Sheet and tried to do something like this:

function test() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Cabins");
  const range = sheet.getRange(4, 27);
  const value = range.getValue();
  Logger.log(value);
}

which gives me a result of "#ERROR!" even though the spreadsheet shows a value of "0" in that cell (R4C27). displayed value of R4C27

Puzzled, I started playing around and copied the exact same formula into a different cell (R1C13) then did this:

function test() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Cabins");
  const range1 = sheet.getRange(4, 27);
  const range2 = sheet.getRange(1, 13);
  const value1 = range1.getValue();
  const value2 = range2.getValue();
  Logger.log(`value1: ${value1}`);
  Logger.log(`value2: ${value2}`);
}

value1 still gives "#ERROR!" but value2 gives the correct response of "0". execution log

Here are the two cells and their formula. First is the problematic R4C27: R4C27

And the working R1C13: R1C13

What could possibly cause the first one to return a range Value of "#ERROR!"?

UPDATE 1: I think I'm getting closer to figuring out the cause, but not the solution. So, my COST custom function will calculate a value, but the later calls to COST lower in the spreadsheet may actually refer to a cell which itself needs to call COST, so it's a recursive function. In this image, the errored cell actually refers to the highlighted cell which also uses COST.

enter image description here

Since all formulas are executed simultaneously when the sheet is loaded, the ones that are recursive will point to cells whose formulae haven't finished yet.

I'm not sure what the solution is but I'm leaning towards converting the cell-based custom formula into a menu item which I can trigger on demand, which will call all the formula in the correct order and ensure that later calls have access to data.

about 4 years ago · Juan Pablo Isaza
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