Word count is a function that returns the number of words in a given text string. This can be useful when you need to count the number of words in a document or a section of text. Here is a custom formula in Apps Script to count the number of words in a given cell:
function wordCount(cell) {
if(cell == "") return 0; // If the cell is empty, return 0
var words = cell.split(" "); // Split the cell contents into an array of words
return words.length; // Return the length of the array, which is the number of words
}
To use this formula, enter =wordCount(A1)
in a cell, where A1
is the cell containing the text you want to count the terms of. This will return the number of words in that cell.
For example, if A1
it contains the text “The quick brown fox jumps over the lazy dog”, the formula =wordCount(A1)
would return 9.