1

I would like to implement a script that checks the values in column "D" of sheet "Review&Trigger". If the value is yes, then it copies the content only of the cells in the same row between columns E and P. Afterwards, it pastes the content to the same range.

For example: if the value in D5 (Important, this applies to any row of column D) is "Yes", then the script should copy the range E5:P5 and paste the values only to the same range E5:P5.

I am pretty new to google script with basic knowledge of it.

I have implemented this code but it does not work:

function onEdit() {
 var s = SpreadsheetApp.getActiveSheet();
 if( s.getName() == "Review&Trigger" ) {
  var r = s.getActiveCell();
  var y = s.getActiveRange();
  if( r.getColumn() == 4 && y.getValue() == "Yes") {
  var nextCell = r.offset(0, 12);
  var range = s.getRange(r,nextCell);
  range.copyTo (range, {contentsOnly: true});
source.clear();
  }
 }
}

Any idea about how to fix the code? Many thanks in advance!

2
  • I doubt var range = s.getRange(r,nextCell); is a right way to use getRange() Commented Jun 22, 2018 at 7:45
  • Thanks Max! I guess that you are right.... Can you help me and shed some light on how I should address it correctly? Commented Jun 22, 2018 at 9:42

1 Answer 1

1

You have options to use getRange():

  1. getRange(row, column). Row and column are numbers.
  2. getRange(row, column, numRows). Numbers.
  3. getRange(row, column, numRows, numColumns). Numbers.
  4. getRange(a1Notation). string like "A1:C15"

After range is defined, use offset to get other range on the same sheet.

Before using onEdit script, test it with usual function. Use Logger.Log('hello world'); or Browser.msgBox('hello world'); to get the info about execution.

See more:

https://developers.google.com/apps-script/reference/spreadsheet/sheet https://developers.google.com/apps-script/reference/spreadsheet/range

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.