Resting Anchor

The Anchorage

Personal website of Gregory K. Maxey, Commander USN (Retired)

Count Lines of Text
(A Microsoft Word Help & Tip page by Gregory K. Maxey)


The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

The purpose of this Microsoft Word Tips & Microsoft Word Help page is to provide help to the frustrated transcriptionist.

Transcriptionists often ask "How do I get an accurate count of lines in my document that actually contain text?"

The Word command "Word Count" generates a report listing the number of lines in a document. The report qualifies “all lines.” This includes lines that are empty but still available for holding text. There is a difference between an empty line (which is counted) and space between lines, which isn't.

count line 1

Have a look at the two samples of text below. They both look the same and they both appear to have 6 lines of text.

count lines 2

However, the "Lines" count in a Word Count report of Sample I text returns eight (8).  Surely a frustratingly inaccurate count for the transcriptionists.

count lines 3

A line count of the Sample II text returns six (6).

count line 4

What is the difference? The first example contains empty lines!!

Toggle display of non-printing characters CTRL+SHIFT+* and you will see in the first example the ¶ paragraph symbol marking an empty line 3 and 5. Are these lines capable of holding text? Certainly! Empty lines are a result of undisciplined formatting. It is very easy and generally a bad habit to create space between lines by pressing the enter key. However, as this example has illustrated, you are not only generating space; you are also adding empty paragraphs, which count as lines.

count lines 5

Sample II, on the other, has disciplined paragraph formatting applied using the "Paragraph" dialog. As an alternative, you can quickly apply this formatting to any selected text with the keyboard shortcut CTRL+0.

count lines 6

Line Counting Macros

Disciplined formatting should eliminate most of your problems with accurate line counting. However, if you refuse to get onboard, I have put together a few macros to overcome the error induced by undisciplined formatting.

  1. The first macro provides an accurate count of empty lines by first eliminating any lines created by undisciplined use of the enter key. It then performs and reports a line count. Finally empty lines are restored in the document.
VBA Script:
Sub CountLinesOfText()
Dim NumLines As Long
  With ActiveDocument.Range.Find
    .Format = False
    .Forward = True 
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Text = "[^13]{2,}"
    .Replacement.Text = "^p"
    .Execute Replace:=wdReplaceAll
    .Text = "[^l]{2,}"
    .Replacement.Text = "^l"
    .Execute Replace:=wdReplaceAll
    .Text = "^13^l"
    .Replacement.Text = "^p"
    .Execute Replace:=wdReplaceAll
    .Text = "^l^l3"
    .Replacement.Text = "^p"
    .Execute Replace:=wdReplaceAll
  End With
  NumLines = ActiveDocument.ComputeStatistics(wdStatisticLines)
  ActiveDocument.Undo 'ActiveDocument.Undo
  MsgBox ("The document contains " & NumLines & " Lines")
  Selection.HomeKey wdStory
Exit Sub
End Sub
  1. The second macro counts lines of qualified length. It is pre-set to skip counting lines that contain a single character (i.e., a paragraph mark or line break mark) and lets you specify a threshold qualifier. For example, if you want to count all lines containing three or more characters (excluding the paragraph mark or line break mark) then you enter 3 in the input box when the macro runs.
VBA Script:
Sub CountQualifiedLines()
Dim CharCount As Integer
Dim tCount As Integer
Dim LineCount As Integer
Dim Qualifier As String
  Qualifier = InputBox("Enter threshold line length." & vbCr + vbCr _
                     & "To be counted the line must contain the " _
                     & "threshold number of characters " _
                     & "(excluding the line end mark.)", _
                     "Line Length", 1)
  tCount = ActiveDocument.ComputeStatistics(wdStatisticLines)
  Selection.HomeKey wdStory
  Do While tCount > 0
    With Selection
      .EndKey Unit:=wdLine, Extend:=wdExtend
      CharCount = .Characters.Count
      tCount = tCount - 1
      On Error GoTo lbl_Exit
      If CharCount > Qualifier Then
        LineCount = LineCount + 1
      End If
      .Collapse wdCollapseStart
      .MoveDown Unit:=wdLine, Count:=1
      .EndKey Unit:=wdLine, Extend:=wdExtend
    End With
  Selection.HomeKey wdStory
  MsgBox "There are " & LineCount & " qualified lines in this document"
  Exit Sub
End Sub

Site Note icon See: Installing Macros for instructions on how to set up and use the macros provided in this Microsoft Word Help & Microsoft Word Tips page.

Site Note iconBonus Tip:  Create your own "Lorem ipsum ..." text in Word 2007/2010 by simply typing =lorem() and pressing enter.  What is "Lorem ipsum?"  See: Lorem Ipsum.  For more dummy text methods see Word MVP Suzanne Barnhill's: Dummy Text  

That's it! I hope you have found this Microsoft Word Help & Tips page useful and informative.



Click to acces PayPal Verification Service Click to acces PayPal Verification Service

Do you want to make a payment for consulting work or donate to help support this site?

PayPal is a safe, easy way to pay online.

Use the appropriate currency "Donate" button to make a payment or donation.

Search my site or the web using Google Search Engine

Google Search Logo