Google Sheets | Edit row of data if duplicate found

manc

Active Member
Joined
Feb 26, 2010
Messages
335
Good afternoon,

I have this code that copies to sheet "INVOICE_ENTRY" any row in the range A5:P if it finds a value in column N.

"INVOICE_ENTRY" sheet is identical to the srcSheet, except it has a couple more columns after P.

What I want to happen is after running the script, if it finds a duplicate record in the dstSheet, and using columns G and H as the identifier, it overwrites the data in dstSheet, rather than adding a new row.

Is this possible?

Code:
Code:
function payINVOICE() {
  var ss = SpreadsheetApp.getActive();
  var ds = SpreadsheetApp.openById("sheetname");
  var srcSheet = ss.getSheetByName("PAY_INVOICE");
  var dstSheet = ds.getSheetByName("INVOICE_ENTRY");

  var data_range = srcSheet.getRange('A5:P');
  var data_data = data_range.getValues();
  var data_clean  = data_data.filter(function (r) {return r[14]});

  var clear_range = srcSheet.getRange('N5:P');



  var lr = dstSheet.getLastRow();

  dstSheet.getRange(lr+1, 2,data_clean.length,16).setValues(data_clean);
  clear_range.clear();

}

Best regards,
manc
 

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Watch MrExcel Video

Forum statistics

Threads
1,102,345
Messages
5,486,323
Members
407,539
Latest member
ltwkuav

This Week's Hot Topics

Top