Counting hyperlinks on Google Sheets formula

怎甘沉沦 提交于 2019-12-13 03:47:57

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/48231263/counting-hyperlinks-on-google-sheets-formula

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!