function copyRows()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var srcSheet = ss.getSheetByName("Form Responses 1");
var tarSheet = ss.getSheetByName("MasterDB");
var lastRow = srcSheet.getLastRow();
var Lr = tarSheet.getLastRow();
for (var i = 2; i <= lastRow; i++)
{
var cell = srcSheet.getRange("A" + i);
var val = cell.getValue();
Logger.log(lastRow)
for(var j=2; j<= Lr; j++)
{
var findstring = tarSheet.getRange("A" + j);
var find =findstring.getValue();
// Logger.log(find)
if (val == find)
{
continue;
}
var srcRange = srcSheet.getRange("A" + i + ":T" + i);
var tarRow = tarSheet.getLastRow();
tarSheet.insertRowAfter(tarRow);
var tarRange = tarSheet.getRange("A" + (tarRow+1) + ":T" + (tarRow+1));
srcRange.copyTo(tarRange);
}
}
}
- Hello ,actually I'm trying copy & paste rows from one sheet to another within the spreadsheet ,but to avoid duplicates ,i'm comparing cell value from column A in both the sheets.
- column A is having Date & Time Stamp ,which i'm comparing ,if value matches ,then don't copy &if not copy the particular range & paste on 'last row' of Master DB.
- But with above code its just keep on copying rows multiple times ,i'm not getting where exactly the error is.
- Please help me with this ,any help will be appreciated ,Thanks in Advance.
- Sorry ,if i have posted this in a wrong format ,actually i'm new here.