Is there an elegant way to do this :
function calculateTotal(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var total =0;
for (i=3;i<=60;i++) {
total=0;
for (j=3;j<=234;j++) {
if (sheet.getRange("B"+j).getValue() == sheet.getRange("J"+i).getValue() &&
(sheet.getRange("B"+j).getFontLines() != 'line-through') ) {
total++;
}
if (sheet.getRange("C"+j).getValue() == sheet.getRange("J"+i).getValue() &&
(sheet.getRange("C"+j).getFontLines() != 'line-through') ) {
total++;
}
if (sheet.getRange("D"+j).getValue() == sheet.getRange("J"+i).getValue() &&
(sheet.getRange("D"+j).getFontLines() != 'line-through') ) {
total++;
}
if (sheet.getRange("E"+j).getValue() == sheet.getRange("J"+i).getValue() &&
(sheet.getRange("E"+j).getFontLines() != 'line-through') ) {
total++;
}
if (sheet.getRange("F"+j).getValue() == sheet.getRange("J"+i).getValue() &&
(sheet.getRange("F"+j).getFontLines() != 'line-through') ) {
total++;
}
if (sheet.getRange("G"+j).getValue() == sheet.getRange("J"+i).getValue() &&
(sheet.getRange("G"+j).getFontLines() != 'line-through') ) {
total++;
}
if (sheet.getRange("H"+j).getValue() == sheet.getRange("J"+i).getValue() &&
(sheet.getRange("H"+j).getFontLines() != 'line-through') ) {
total++;
}
}
sheet.getRange("K"+i).setValue(total);
}
}
In pseudo code it would be
for cellUpdate in range #the column being updated
for cellScan in range #the rows and columns being scanned
if isNotStruckOut(cellScann) total++
cellUpdate = total
I can write functions to check for color which I need to, but there has to be a better way to loop over a column and then a sheet/range.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…