Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To find the number of lines of text present in a cell 1

Status
Not open for further replies.

vignesh1980

Programmer
Jan 8, 2006
2
US
Hi,
Can any one help with the code to find out the number of lines of text present in a cell in excel.
 
Can you clarify please ... do you want to know how many embedded line-feeds are in the contents of a cell? Or do you want to know how text wrapping has affected a cell?

Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
Hi Glenn,

Sorry for the delay in responding. I want to exactly how text wrapping has affected a cell. That is if a cell has more text it is wrapped into 3 or 4 lines, at this instance how to find out the number of lines in the cell.

 
This is a kludge and won't be exact, but:
Code:
Public Function CountTextLines(InRow As Long, Optional StdRowHgt As Double = 12.75) As Integer
    
    If (StdRowHgt > 0) Then
        CountTextLines = Int(ThisWorkbook.Worksheets(1).Cells(InRow, 1).RowHeight / StdRowHgt)
    Else
        CountTextLines = 0
    End If
    
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top