I have two separate scripts that work. The first checks a column in one(Master)worksheet against a column in a different(Dependent)worksheet. If it finds a match, it copies that row from the (Dependent) to the (Master) worksheet.
The second script compares two arrays(one from the Master and one from the Dependent) and changes the background on the Master if they are not the same.
Since both compare arrays, is there a way to combine these two functions?
I've gotten some help from these boards previously and have tried to combine the code on my own. However, my knowledge of scripting...specifically arrays is quite limited.
var MSsId='Master_Sheet_ID';
var mshName='Sheet1';
var DSsId='Dependent_Sheet_ID';
var dshName='Sheet2';
function findMatchesAndCopy() {
var mss=SpreadsheetApp.openById(MSsId);
var msh=mss.getSheetByName(mshName)
var mrg=msh.getRange(3,1,msh.getLastRow()-2,5);
var mvA=mrg.getValues();
var dss=SpreadsheetApp.openById(DSsId);
var dsh=dss.getSheetByName(dshName);
var drg=dsh.getRange(3,1,dsh.getLastRow()-2,5);
var dvA=drg.getValues();
var mmA=mvA.map(function(r){return(r[0])});
for(var i=0;i<dvA.length;i++) {
var idx=mmA.indexOf(dvA[i][0]);
if(idx>-1){
mvA[idx]=dvA[i];
}
}
mrg.setValues(mvA);
}
// var bgs=mrg.getBackgrounds(); This is the code
// for(var i=0;i<bgs.length;i++) { that checks the
// for(var j=0;j<bgs[i].length;j++) { array background.
// if(mvA[i][j]!=dvA[i][j]) { I can't figure out
// bgs[i][j]='#ffff00'; how to adapt and insert
// } this into the rest of
// } the code
// }
// mrg.setBackgrounds(bgs);
//
In short, I'd like to have this script compare a Dependent sheet to the Master sheet...and if there are any differences, copy and highlight them on the Master
combine these two functions. I would like to correctly understand your goal and think of the solution. I apologize for my poor English skill.