Max character for each column.

J

Joergen Bondesen

Hi NG.

I have a spreadsheet with 7 columns and 150000 rows.

For each column i want to know max. character include spaces.

I can test all cells, one by one per column, but I need at faster way.

Any suggestion?
 
L

Lars-Åke Aspelin

Hi NG.

I have a spreadsheet with 7 columns and 150000 rows.

For each column i want to know max. character include spaces.

I can test all cells, one by one per column, but I need at faster way.

Any suggestion?

Try the following formula to get the max number of characters in
column A from line 1 to 150000

=MAX(LEN(A1:A150000))

Note: The formula must be entered as an array formula, i.e. with
CRTL+SHIFT+ENTER rather than just ENTER.

Hope this helps / Lars-Åke
 
A

Alan Moseley

Use an array formula at the bottom of each column. For example if you want
to see the longest strings in cells A1 to A150000 use the formula:-

=MAX(LEN(A1:A150000))

Don't just press enter after entering this formula, hold down Crtl and Shift
and then press enter.
 
J

Joergen Bondesen

Hi Lars-Åke

Thanks, it works, but I need a VBA solution. My mistake, sorry.
 
J

Joergen Bondesen

Hi Alan

Thanks, it works fine, but I need a VBA solution. My mistake, sorry.
 
C

Chip Pearson

You can use the Evaluate method to have Excel parse and calculate a
formula passed in as a string. E.g.,

Dim L As Long
' watch for the pairs of " characters.
L = Application.Evaluate("=MAX(LEN(""A1:A100""))")
Debug.Print L

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
D

Dave Peterson

Just to add to Chip's response...

I think I'd use this:

L = worksheets("Sheet999").Evaluate("=MAX(LEN(""A1:A100""))")

Then I wouldn't have to worry about what worksheet was active when the code ran.
 
C

Chip Pearson

Just to add to Chip's response...
I think I'd use this:

Good catch. You're absolutely correct.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
J

Joergen Bondesen

Hi Chip and Dave


Thank, but i do not work for me.
L = 7 Why ?

Do you have any suggestion?

I'm using Danish Excel 2007 and Danish Win XP


Info Len
abc 3
abc abc 8
abcdefghij 10
1232 4



Option Explicit

Sub test()
Dim L As Long
L = Worksheets("Test").Evaluate("=MAX(LEN(""A1:A100""))")

MsgBox L
End Sub

L must be = 10
 
D

Dave Peterson

Try:
L = Worksheets("Test").Evaluate("MAX(LEN(A1:A100))")

You don't need the leading = sign (but it won't hurt).

And Chip got enthusiastic with those double quotes <vbg> (and I didn't notice).

So you were really finding the length of this string:
A1:A100
Which is exactly 7 characters!
 

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