Skip to content

Instantly share code, notes, and snippets.

@easement
Last active September 6, 2017 22:27
Show Gist options
  • Save easement/b450bd4c82ac2fa89039178cb0814c3a to your computer and use it in GitHub Desktop.
Save easement/b450bd4c82ac2fa89039178cb0814c3a to your computer and use it in GitHub Desktop.
Something to loop through a google sheet and do conditional values
function who_is_out() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getSheets()[0];
var selection=sheet.getDataRange();
var columns=selection.getNumColumns();
var rows=selection.getNumRows();
var outages; // keep running list of game outages
var outageCell; // the cell to update with outages
var personCell; // keeping track of the name for easier readability
var currentCell; // cell used for traversal
for (var row=1; row < rows; row++) {
outageCell=selection.getCell(row,2);
outageCell.setValue(''); // Clear it out each run
outages = []; // init each row for keeping track
for (var column=1; column < columns; column++) {
currentCell=selection.getCell(row,column);
if (currentCell.getValue() == "Out") {
personCell=selection.getCell(1,column); // get person name
outages=outages.concat(personCell.getValue()); // add someone to the out list
}
outageCell.setValue(outages.join(", ")); // csv the list of outages and put in the cell.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment