1.打开vba管理器
alt F11直接打开
或者 文件
-> 更多
-> 选项
-> 自定义功能区
-> 开发工具
2.编写脚本
右键插入一个模块
双击这个模块名, 会弹出一个框框, 把代码粘贴进去, 然后ctrl s保存
Function CountWords(rng As Range) As Long
Dim cell As Range
Dim wordCount As Long
wordCount = 0
For Each cell In rng
wordCount = wordCount + Len(cell.Value)
Next cell
CountWords = wordCount
End Function
3.保存文件
如果是你普通excel文件,保存宏时肯定会提示你: 你的文件没启用宏, 是否存一下, 你选择xlsm
格式另存为即可, 或者直接在主界面另存为
4.使用
在任意单元格输入=CountWords(A1:B10)
, 就可以按区域统计了