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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate the Max Field Length 2

Status
Not open for further replies.

V00D00

Technical User
Jul 11, 2005
78
US
I am looking for a way to calculate the longest field length in use for a given column in excel. A formula or VBA solution would be most greatly appreciated.

VD
 
Brute force method in VBA:
longest = 0
For Each c In yourcolumnRange
l = Len(Trim(c.Text))
If l > longest Then longest = l
Next
MsgBox "longest = " & longest

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Formula method:
Code:
=MAX(LEN(A2:A65536))
entered using Ctrl-Shift-Enter.

Note: the length of the range is 1 less than the total number of cells in a column. This had been done on purpose, as in most versions of Excel having all cells in a column in a formula like this will result in the #NUM! error.

Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top