Last active
March 16, 2018 20:18
-
-
Save AndresMWeber/3d9a20cbd5006fb931d7a7acab915cde to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Counts a guest's name that is not highlighted nor has strikethrough | |
* | |
* @return The value of all the guests. | |
* @customfunction | |
*/ | |
function COUNTGUESTS(){ | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var formula = SpreadsheetApp.getActiveRange().getFormula(); | |
var args = formula.match(/=\w+\((.*)\)/i)[1].split("!"); | |
try { | |
if (args.length == 1) { | |
var range = sheet.getRange(args[0]); | |
} | |
else { | |
sheet = ss.getSheetByName(args[0].replace(/'/g, '')); | |
range = sheet.getRange(args[1]); | |
} | |
} | |
catch(e) { | |
throw new Error(args.join("!") + " is not a valid range"); | |
} | |
var weights = range.getFontLines(); | |
var values = range.getValues(); | |
var colors = range.getBackgrounds() | |
var guests = 0; | |
for (var i = 0; i < values.length; i++) { | |
for (var j = 0; j < values[0].length; j++) { | |
if (weights[i][j] != "line-through" && colors[i][j] == "#ffffff" && values[i][j] != "") { | |
guests += 1; | |
} | |
} | |
} | |
return guests; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment