Clear the contents of each row in a column on one sheet, depending on the change in a column on the same row on another sheet

Mac

I'm struggling with this code, which works perfectly inside the same sheet, to get it work between two sheets. For an example if I change a content in cell E5 or in multiple cells in E column on "Sheet1", this clears a content in Cell A5 or in multiple cells in A column, depending on the row they are in.

function onEdit(e){
  var range = e.range;
  var row = range.getRow();
  // Check if column E and sheet "Sheet1"
  if(range.getColumn() == 5 && range.getSheet().getName() == "Sheet1") 
  {
    if(range.getHeight()>1)
    {
      // Multiple cells selection case
      var nbRow = range.getNumRows();
      var i;
      for(i =0; i < nbRow; i++)
      {
        var temp = row + i;
        e.source.getRange("A"+temp).clear();
      }
    }
    else
    {
      // One cell selection case
      e.source.getRange("A"+row).clear();
    }
  } 
}

Could any of you guys please help me with the code to get it work between two sheets, because it's already driving me crazy :/

Any help would be greatly appreciated!

Cooper

Change in one sheet clears range in another sheet

function onEdit(e){
  var sh=e.range.getSheet();
  if(sh.getName()=='Sheet1' && e.range.columnStart==5) {
    var sh2=e.source.getSheetByName('Sheet2');
    sh2.getRange(e.range.rowStart,1,e.range.rowEnd-e.range.rowStart+1,1).clearContent()  
  }
} 

Question: What should I do to the code so it starts on the fifth row? First four rows are frozen. (Probably header info)

function onEdit(e){
  var sh=e.range.getSheet();
  if(sh.getName()=='Sheet1' && e.range.columnStart==5 && e.range.rowStart>4) {
    var sh2=e.source.getSheetByName('Sheet2');
    sh2.getRange(e.range.rowStart,1,e.range.rowEnd-e.range.rowStart+1,1).clearContent()  
  }
} 

Animation:

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Change value of a cell depending on contents of column of another google sheet

Transfer a Range in a column in one sheet to a row in another sheet

subtract the contents of one column from another columns in each row

Google sheet script : Delete row depending on column content

trying to copy a row and the row before it to another sheet based on a value in column A

Highlight row if column value partially matches in another sheet column

Google Sheet - Filter by ROW and COLUMN

Index only cells in a column from another sheet if another cell in same row has a value greater than 0

GSheets copying a row in one sheet to another sheet, which contains the same row

Finding a value in a row on another sheet and placing a value in the matching row and column header on current sheet if exists and 0 if it doesnt

Take value of each column of Google Sheet row and apply formula to it

Is there a way to change the contents of a ComboBoxTableCell depending on the row and column that is being edited?

How do I search Column O for a value listed on another sheet and change row color?

Moving data from one row to another in the same sheet with a check box

Transferring certain cells from one sheet to another in excel despite column/row insertion/extraction

Copy every nth column on a specific row from one sheet to another (in Google Sheets)

VBA (Excel) to copy a row of data from one sheet to another if a column contains data

When a row is added to one sheet, automatically add a row to another sheet

Copy Row from one Sheet to another sheet which is linked in the row

getting data from another sheet using row and column number

Replace Headers name in the first row from the cells column of another sheet

Macro to insert data into next blank row or column in another sheet?

Search on specific row for value, copy entire column to another sheet

Finding the cell value from another sheet basing on row/column index

getting the value of a cell from another sheet with a fixed column and a variable row

Copy every second value of a row and paste into a column in another sheet

How to copy data from one sheet using column name and paste to another sheet with same column name?

how to copy text from column of active sheet and past it to another sheet according to the specific row and column number which are in active sheet

Loop through each cell in a given range and change the value depending on value in a column in the same row