Back to Browse

Create VBA to do a Word Count

339 views
May 24, 2020
11:06

In this video I demonstrate how to create a VBA macro that will do a word count on your active sheet. Note that before the vbNullString is a less than and greater than sign but YouTube will not allow angular brackets. VBA code below: Sub WordCount() Dim WordCnt As Long Dim rng As Range Dim S As String Dim N As Long For Each rng In ActiveSheet.UsedRange.Cells S = Application.WorksheetFunction.Trim(rng.Text) N = 0 If S () vbNullString Then N = Len(S) - Len(Replace(S, " ", "")) + 1 End If WordCnt = WordCnt + N Next rng MsgBox "There are a total " & Format(WordCnt, "#,##0") & " words in the active worksheet" End Sub

Download

0 formats

No download links available.

Create VBA to do a Word Count | NatokHD