0

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.

Leon K.
  • 115
  • 2
  • 12
  • "it didn't work" is not a valid problem description. https://stackoverflow.com/help/how-to-ask – tehhowch Aug 29 '18 at 20:16
  • Sorry, I did not understand, and I corrected the part of the question, Thank you `tehhowch` – Leon K. Aug 29 '18 at 20:30
  • You could try to check if the line before is the same than the one you want to insert. Also, if you want to respond to someone you can use @username, this way they'll get a notification – Liora Haydont Aug 29 '18 at 20:46
  • @LuisAvl Please see: [Why is “Can someone help me?” not an actual question?](http://meta.stackoverflow.com/q/284236). It's good you have reviewed some past questions, but you need to be clear about what you have tried and the specifics of how it did or did not work towards your goal. – tehhowch Aug 29 '18 at 20:56
  • @tehhowch Thanks, the truth is that I did not know about what you say, I just put that so that the question would be nicer but seeing the post I realize that you are right. – Leon K. Aug 29 '18 at 21:11
  • @LioraHaydont - The problem is that it is not just a data but rather it is that several spreadsheets pass their data to a single spreadsheet that is the master spreadsheet – Leon K. Aug 29 '18 at 21:11

0 Answers0