Google Sheets | Edit row of data if duplicate found

manc

Active Member
Joined
Feb 26, 2010
Messages
340
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
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top