Home > database >  Google Sheet Copy Column Data On Edit
Google Sheet Copy Column Data On Edit

Time:06-15

I had entered a formula in column B of the Google Sheet (link given below) which will generate number if I enter data in Column C.

I want to design a script which will run when data is entered in column C and the script will copy the number generated in column B in column A.

https://docs.google.com/spreadsheets/d/1kfa9pkItGQGaWWD_L8opR9w-MZnWxA2qfBTmNYp0wmg/edit?usp=sharing

Any help on above will be appreciated.

CodePudding user response:

Issue:

If I understand you correctly, you want a script to do the following:

  • Fire every time column C is edited.
  • On the edited row, copy the value from column B to column A.

Solution:

In that case, you can use a simple onEdit trigger and the corresponding event object, like this (check inline comments):

function onEdit(e) {
  const range = e.range; // Edited range, from event object
  if (range.getColumn() === 3) { // Check edited column is C
    const b = range.offset(0,-1).getValue(); // Get value from B
    if (b !== "") { // Check B is not empty 
      range.offset(0,-2).setValue(b); // Set value in A
    }
  }
}
  • Related