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

202
Views
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 answers
Answer question

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 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!