Last active
June 14, 2021 17:55
-
-
Save natalyjazzviolin/d02477510f37f8d8db1af8c49d505911 to your computer and use it in GitHub Desktop.
A script to copy student grades from one sheet to another.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Trigger function | |
function sheetTrigger() { | |
ScriptApp.newTrigger("copyData") | |
.timeBased() | |
.everyMinutes(1) | |
.create(); | |
} | |
//Copy function | |
function copyData() { | |
//Get source range | |
var source = SpreadsheetApp.openById('SHEET ID'); //Separate spreadsheet | |
var sourceSheet = source.getSheetByName('Week of April 5'); //Sheet tab with source data | |
var sourceValues = sourceSheet.getDataRange().getValues(); // get data from source | |
//Get target range | |
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Week of April 5"); | |
let targetValues = targetSheet.getDataRange().getValues(); | |
//Set source value for each target value | |
targetValues.forEach(function(targetRow, x) { | |
sourceValues.forEach(function(sourceRow, y) { | |
if (sourceRow[1] != targetRow[1] && sourceRow[2] != targetRow[2]) { | |
} | |
else if (sourceRow[1] == targetRow[1] && sourceRow[2] == targetRow[2]) { | |
let range = targetSheet.getRange(Number(x+1), 10) | |
console.log(range); | |
range.setValue(sourceRow[9]); | |
} | |
}) | |
}) | |
console.log(sourceValues) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment