I need to know how I can copy some data but if the values are already in the spreadsheet do not bring duplicates. I have a code that its function is to copy from a spreadsheet the last value of certain columns to a spreadsheet master to the last available row and what I need is that every time I update the spreadsheet master it does not bring me a duplicate value, an example with which I can better explain this is:
Spreadsheet Spreadsheet Master
A B A B
Jhon 1 Carl 3
Lois 2
Carl 3
And if a new value is added to the spreadsheet and run the script two times, it looks like this:
Spreadsheet Spreadsheet Master
A B A B
Jhon 1 Carl 3
Lois 2 Tom 4
Carl 3 Tom 4
Tom 4
And I do not want me to bring back the same value duplicated. The script it's the next one...
function getValues() {
var bring = SpreadsheetApp.openById(ID);
var sh1 = bring.getSheetByName("Sheet 1");
var ltRow = sh1.getLastRow();
var rgSh1 = sh1.getRange("A"+(ltRow)+":D"+(ltRow)).getValues();
var rgSh2 = sh1.getRange("F"+(ltRow)).getValue();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh2 = ss.getSheetByName("Sheet 1");
var getRow = sh2.getLastRow() + 1;
var sRgSh1 = sh2.getRange(getRow, 2, rgSh.length, rgSh[0].length).setValues(rgSh);
var sRgSh2 set= sh2.getRange(getRow, 1).setValue(rgSh1);
}
And I was trying to do it with a For and a nested For but it does not work out I was also seeing examples like this: Stackoverflow but in these example the operation is different from what I try to do and I've been trying but I have not yet achieved it. Thanks.