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

203
Visualizações
Paste the static value in the column besides if the particular cell is empty in google sheets

I might not be able to explain better, but I will try my best. I have two columns say A and B, in column A there are formulas so values in them get changed depending on some other conditions, Now what I want in column B is to paste/setvalue the value for the first time whenever a value appears in column A, so that when there are any further changes in column A, it wouldn't affect the value that is pasted in column B. Although I have tried my best to write the script, it does paste the value but it pastes in all the column and does not care if any cell in column A is empty.

I have gone through a lot of research but could not find an answer. Although OnEdit can work but as the column from which the value is to be got has formulas in it and OnEdit doesn't work on formulas. So once the script is corrected, we can trigger it to time driven.

I just need the help to make this function work correctly, I will be highly thankful for any help. thank you.

function pastevalue(){
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
  var lastrow = ss.getRange("A2:B").getValues().filter(String).length;
  var range = ss.getRange(2,1,lastrow);
  var pasterange = ss.getRange(2,2,lastrow);
  var values = range.getValues().filter(String);
  var pastevalues = pasterange.getValues();

  for (i=0; i<values.length; i++){
    if(pastevalues[i] == ""){
        var value = pasterange.setValue(values[i])
    }
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I presume that your goal is to grab the numerical value of a formula immediately after you enter it, so that if the displayed value in the cell of the formula changes in the future, you still possess the original value that the formula yielded. The following script accomplishes that:

function onEvent(e){
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");

  if (e.range.getColumn() == 1 && typeof e.oldValue == 'undefined'){
    sheet.getRange(e.range.getRow(), 2).setValue(e.range.getValue());
  }
}

Note that it is an event trigger, meaning it runs every time the spreadsheet is, well, edited. As the parameter of the function we grab the event that triggered the script (you can read how they are structured here), and then we check for two conditions that both have to be true to copy the value into the B column:

  • First we check that the column of the cell modified is the A (1st) column.
  • Then we check that the cell was blank before modification. This will mean that the value will only be copied when a formula is written in a blank cell.
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