How do you count hyperlinked numbers within a simple Google Sheet formula? Currently the =SUM(F6:CS6) (for example) does not count cells with hyperlinks.
2 Answers
This requires a custom function, because built-in functions cannot detect what formulas are entered in other cells, they can only access values. The discussion at Google Product Forum confirms this. There is already a custom function posted there, but I wrote another one, a bit shorter and not case-sensitive:
function countLinks(rangeNotation, range) {
var formulas = SpreadsheetApp.getActiveSheet().getRange(rangeNotation).getFormulas();
return formulas.reduce(function(acc, row) {
return acc + row.reduce(function(acc, formula) {
return acc + (/^=HYPERLINK/i.test(formula) ? 1 : 0);
}, 0);
}, 0);
}
Usage example: =countlinks("A2:E10", A2:E10)
. Range notation has to be passed in as a string, because the function needs the range, not the values. But this also means it needs the second parameter to be recalculated in case something changes in the referenced range.
Warning: this only counts the hyperlinks created with hyperlink
formula. It will not detect the links created by pasting rich text into a cell. Those links (which really should never be created) are not detectable with Google Apps Script at present.
If you dont want to use scripts and just want a formula, this might serve you: Countifs in Google Sheets with various 'different than' criteria in same row adds +1 value
Particularly, the answer about the function COUNTA might be what you are looking for.