# Maximum Text Length

You may be working with lists in Excel.  They may get a little wide and you might like to cut down the size of some of the columns.  If you could just easily find where the longest values were so you could cut them down in size.

The exercise and the result are in the Text Length file.

We have a column of company names as part of a list.  For simplicity, we will just show this column.

It is wider than we would like.  We want to cut down the width of our overall list.

What is the longest company name?  You may recall the formula for the length of cell A2 is:

=LEN(A2)

You may also recall one of the skills we have taught is working with arrays, which allows you to do calculations on an entire range at once.  We called gave this range a name ("company") and by using an array, we can quickly generate the maximum length for the whole list.

Our formula converted for an array is:

{=MAX(LEN(company))}

The parts are:

• LEN(company)-  to get the length of any cell in the range named "company"

• MAX(LEN(company))- get the maximum length

• {=MAX(LEN(company))}- save the formula as an array (by clicking Ctrl, Shift and Enter at the same time).

We played a trick to demonstrate an error.  Usually if you try to save an array formula, but accidentally save it as a regular formula by clicking Enter only, you will get an error.  That did not happen in the above screen shot.  Instead we got a meaningless number.  When we save it properly (which you can tell by the brackets around the formula), we get the correct value of 65 for the maximum length.

It is good to know the maximum length.  But can we find the cell with the maximum length?

This formula is a little more involved, let's walk you through it:

{=MATCH(C3,LEN(company),FALSE)}

• We use the MATCH function, which returns a row number
• C3- The value we are trying to match is the maximum length, which we already calculated in C3
• LEN(company)- the second argument in the MATCH function is the range being used.  The range is not the company range (i.e. the names of the companies), but rather a range of the lengths of each company name, hence LEN(company).
• FALSE- for the type of match-

Now we know where to go to shorten the company name.  But wouldn't it be nice to see it first before we go to that cell, especially if we have a long list?  Here you go:

For the solution, we use the INDEX function, which consists of:

• What is the range- in this case company
• What location in the range- in this case the row number

INDEX, as we covered in a past lesson, returns the corresponding value from that spot in the range.  Note that this is a formula that by design looks at a range, so we do not need to save it as an array.

With that information, we can decide if we want to cut out the second part of the name (after "/") for example.

Play around with the file.  Trim this one down.  See what is the next longest.  How much you can cut down the column width?

We consider this an advanced formula.  Even if you forget it, you know where to go for the Excel Tips Index, where you can then link to this sheet and have the file handy to cut and paste the formula.  We hope this helps you manage your lists.