none
Counts lines in a table cell RRS feed

  • Question

  • Is there a way to count the lines in a table cell?  I have tried

    Selection.Range.ComputeStatistics(Statistic:=wdStatisticLines)

    with cell selected, but it returns a 0.

    Monday, March 12, 2012 2:21 AM

Answers

  • Hi Orlandp,

    To can get the line count you to exclude the end-of-cell marker from the range. Accordingly, you could use something like:

    Dim Rng As Range
    Set Rng = Selection.Cells(1).Range
    Rng.End = Rng.End - 1
    MsgBox Rng.ComputeStatistics(wdStatisticLines)

    or:

    Dim Rng As Range
    Set Rng = ActiveDocument.Tables(1).Cell(1, 1).Range
    Rng.End = Rng.End - 1
    MsgBox Rng.ComputeStatistics(wdStatisticLines)


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by orlandp Tuesday, March 13, 2012 12:22 AM
    Monday, March 12, 2012 2:51 AM