I am trying to create a script that will pull a value from column[3] in the ZONE sheet to the active sheet, specifically in column 56 of the job sheet when the zonelist value matches the zone value in different sheets. The script should check the range from row 2 to the lastRow in the Job sheet and set the corresponding value from the zone sheet to each respective cell in the job sheet. However, when I run the script, it is displaying the same value in all rows of column 56 in the job sheet instead of transferring the appropriate values based on matching zones.
function UpdateZoneRate(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName('JOBS');
var jobSheet = ss.getSheetByName('JOBS');
var zoneSheet = SpreadsheetApp.openById(
"1jbG_PLWU_eXfQTkwUn1krtYfzniw7HwnwnunhohzL61").getSheetByName('ZONE');
var lastzone = zoneSheet.getLastRow();
var zoneList = zoneSheet.getRange(2,1,lastzone,4).getValues();
var newProd = jobSheet.getLastRow();
var productCode = jobSheet.getRange(2,16,newProd,1).getValue();
var newZone = jobSheet.getLastRow();
var zone = jobSheet.getRange(2,53,newZone,1).getValue();
for (j = 0;j <zoneList.length;j++){
if (zoneList[j][0] == zone && productCode.match(/^A/i))
var aggZone = zoneList[j][3];
jobSheet.getRange(2,56,newZone,1).setValue(aggZone)}
}
SAMPLE VALUES FROM ZONESHEET ZONE1 2 ZONE2 4 ZONE3 6
CURRENT OUTPUT FROM SCRIPT ZONE1 2 ZONE2 2 ZONE2 2
CORRECT OUTPUT REQUIRED FROM THE SCRIPT ZONE1 2 ZONE2 4 ZONE2 4
Thank you for any assistance