Skip to content

Instantly share code, notes, and snippets.

@ashblue
Created April 8, 2017 23:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashblue/0d35c1730f14a924cff093cf3ee0e220 to your computer and use it in GitHub Desktop.
Save ashblue/0d35c1730f14a924cff093cf3ee0e220 to your computer and use it in GitHub Desktop.
Google script for counting words in cell ranges.
function onOpen() {
var menu = [{name: 'Count Words', functionName: 'countWords'}];
SpreadsheetApp.getActive().addMenu('Count', menu);
}
function countWords() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getActiveRange().getValues();
var s = "";
for (var i in data) {
for (var j in data[i]) {
var v = data[i][j];
s += v + " ";
}
}
s = s.trim();
var sa = s.split(" ");
var sCount = sa.length;
Logger.log(sa);
Logger.log(sCount);
sheet.appendRow(['Word Count', sCount]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment