Line Count in Column

S

Stefan Blom

Sure. If you are using Word 2010 (or 2007), click the Page Layout tab,
and then click Line Numbers.
 
J

Jack Fredrick

Sure. If you are using Word 2010 (or 2007), click the Page Layout tab,
and then click Line Numbers.

Sorry I wasn't clear enough, I'm not interested in inserting line
numbers in the document, I want to retrieve the number of lines for a
given column (using vba), or even better to compare the number of
lines in each column on the same page.
 
S

Stefan Blom

See if Selection.Information(wdFirstCharacterLineNumber) or
<RangeObject>.Information(wdFirstCharacterLineNumber) gives you what you
want. I'm afraid I have never worked with line numbers in VBA.
 
J

Jack Fredrick

See if Selection.Information(wdFirstCharacterLineNumber) or
<RangeObject>.Information(wdFirstCharacterLineNumber) gives you what you
want. I'm afraid I have never worked with line numbers in VBA.

Well this is what I found, Assuming a column could be set as a
range(?) the following code was suggested by Chris Greaves to return
line numbers for both beginning and end of column as well as the total
line count for the column..

Function lngLineStart(rng As range) As Long

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Function: lngLineStart
''' Comments: Return LONG the line number at the start of the
given range.
''' Arguments: RANGE The range of text being
examined.
''' Returns: LONG
''' Comments:
'''
''' Date Developer Action
'''
--------------------------------------------------------------------------
''' 2011/02/11 Chris Greaves Created
'''
lngLineStart = rng.Information(wdFirstCharacterLineNumber)
'Sub TESTlngLineStart()
' MsgBox lngLineStart(Selection.Range)
'End Sub
End Function

Function lngLineEnd(ByVal rng As range) As Long

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Function: lngLineEnd
''' Comments: Return LONG the line number at the end of the
given range.
''' Arguments: RANGE The range of text being
examined.
''' Returns: LONG
''' Comments:
'''
''' Date Developer Action
'''
--------------------------------------------------------------------------
''' 2011/02/11 Chris Greaves Created
'''
Dim rng2 As range
Set rng2 = rng
rng2.Start = rng.End + 1
lngLineEnd = rng2.Information(wdFirstCharacterLineNumber) - 1
'Sub TESTlngLineEnd()
' MsgBox lngLineEnd(Selection.Range)
'End Sub
End Function

Function lngLineCount(ByVal rng As range) As Long

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Function: lngLineCount
''' Comments: Return LONG the count of lines in the given range.
''' Arguments: RANGE The range of text being
examined.
''' Returns: LONG
''' Comments:
'''
''' Date Developer Action
'''
--------------------------------------------------------------------------
''' 2011/02/11 Chris Greaves Created
'''
Dim lngS As Long
lngS = lngLineStart(rng)
Dim lngE As Long
lngE = lngLineEnd(rng)
lngLineCount = lngE - lngS + 1
If lngLineCount = 0 Then ' only a part of line was given
lngLineCount = 1
Else
End If
'Sub TESTlngLineCount()
' MsgBox lngLineCount(Selection.Range.Paragraphs(1).Range)
'End Sub
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top