I believe you want to retrieve the number of cells including the formulas on all sheets in a Google Spreadsheet. If my understanding is correct, I would like to propose to use Google Apps Script. So how about this sample script?
I thought that when various approaches are proposed, they might be useful for users. So I would like to propose the following 2 sample scripts.
Pattern 1:
In this pattern, all sheets are retrieved from the active Spreadsheet, and the number of cells including formulas are retrieved from each sheet. In order to count the number of elements, the 2 dimensional array is flatten.
Sample script:
function myFunction() {
const res = SpreadsheetApp
.getActiveSpreadsheet()
.getSheets()
.reduce((n, s) => n += s.getDataRange().getFormulas().flat().filter(String).length, 0);
console.log(res)
}
Pattern 2:
In this pattern, the formulas are retrieved using TextFinder. In this case, all formulas can be retrieved from all sheets in the active Spreadsheet without using the loop process. The detail process for searching is run at the internal server of Google side. In my environment, it is found that the process cost of this pattern was lower than that of pattern 1. Under the same condition, the cost of pattern 2 was about 1/5 of the cost of pattern 1.
Sample script:
function myFunction() {
const res = SpreadsheetApp
.getActiveSpreadsheet()
.createTextFinder("^\\=")
.matchFormulaText(true)
.useRegularExpression(true)
.findAll().length;
console.log(res)
}
Note:
- Both patterns return the same result.
- Please run the script with enabling V8.
References: