Count Words in Spreadsheet in Excel VBA

In this post, you’ll learn how to count words in your excel spreadsheet using Excel VBA.

Count Words in Spreadsheet in Excel VBA

To count words in a spreadsheet,

First, insert a command button then add the following codes:

Code:

Private Sub CommandButton1_Click()

Dim sheet As Range, cell As Range

Dim txtinCell, wordsinRange As Integer, text As String

Set sheet = Selection

txtinCell = 0

wordsinRange = 0

For Each cell In sheet

    If Not cell.HasFormula Then

        text = cell.Value

        text = Trim(text)

        If text = "" Then

            txtinCell = 0

        Else

            txtinCell = 1

        End If

        Do While InStr(text, " ") > 0

            text = Mid(text, InStr(text, " "))

            text = Trim(text)

            txtinCell = txtinCell + 1

        Loop

        wordsinRange = wordsinRange + txtinCell

    End If

Next cell

MsgBox " Total No. of words found =" & wordsinRange

End Sub
Count Words in Spreadsheet in Excel VBA

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn how to Find Blank cells in excel so that you can remove or delete the blank cells form...
In this article, you’ll learn what is a Gauge Chart in Microsoft Excel. Also, you will learn how to add...
Microsoft Excel provides a shortcut for the users to move columns in excel using two different ways – using Shift...