Excel

TheSmallman.com

an XL ideas Lab

Dashboards VBA
  • Home
  • Dashboards
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
    • Power Pivot a User Guide
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About
Menu

Excel Dashboards VBA

Street Address
City, State, Zip
Phone Number
an XL ideas Lab

Your Custom Text Here

Excel Dashboards VBA

  • Home
  • Dashboards
  • Excel Tips
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
  • PowerPivot
    • Power Pivot a User Guide
  • Courses
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About

Excel Maximum Cell Length in a Range

February 29, 2016 Marcus Small

Finding the maximum length string in a range of cells can be handy especially if you are using the max length for another purpose.  The following custom function will find the maximum cell length in a range.

Function LongString(rng)
   LongString = Evaluate("Max(len(" & rng.Address & "))")
End Function

The custom function is called as follows:

= LongString(A1:A10)

So in a range of cells from A1:A10 the custom function will work out the cell with the maximum length and return that number.

A custom function is a bit of overkill if you want to get into some array formula.  The following:

{=MAX(LEN(A1:A10))}

The formula is confirmed with Ctrl Shift & Enter.

If the field name with the most characters is what you are after then incorporating an INDEX and MATCH formula is a way to get a solution.

{=INDEX(A1:A10,MATCH(MAX(LEN(A1:A10)),LEN(A1:A10),0))}

Once again the formula is confirmed with Ctrl Shift & Enter. 

The formula is in 4 parts, the INDEX formula is driving the result

INDEX(Result Range, Row Number, Column Number)

Result Range = A1:A10

ROW Number

The MATCH formula decides the Row number in our case, so the MATCH function is

MATCH(Match Criteria, MATCH RANGE, MATCH TYPE)

The Match criteria = maximum length of the cell.

Match Array or Range is the range where that max is stored.

Match Type = In this case it is an Exact match which is 0 or FALSE (they mean the same thing but 0 is shorter to type.

Column Number - in this case it is not required.

So with CTRL SHIFT and ENTER at the same time the array formula is formed and a result is achieved..

Tags Excel, max, String, range, Custom Function
← Union An Excel Range and Transpose Excel VBA Filtering on Time →

Featured Posts

Excel Dashboards: Tracking a Crisis

Excel Dashboards: Tracking a Crisis
April 14, 2020

Recent Posts

Populating an Excel Table from a Range of Cells with VBA

Populating an Excel Table from a Range of Cells with VBA June 12, 2025

Fuzzy Distribution with Randbetween

Fuzzy Distribution with Randbetween May 21, 2025

Add Minimum and Maximum for Chart in Cells

Add Minimum and Maximum for Chart in Cells March 12, 2025

Inflation Over Multiple Years in a Single Cell

Inflation Over Multiple Years in a Single Cell January 10, 2025

Hubspot Dashboard

Hubspot Dashboard October 3, 2024

Monthly Dashboard With Supporting Metrics

Monthly Dashboard With Supporting Metrics September 25, 2024

Excel Show Missing Sheet Tabs

Excel Show Missing Sheet Tabs July 29, 2024

Run Macro Overnight Automatically

Run Macro Overnight Automatically June 24, 2024

Split File into Parts and Save to Directory

Split File into Parts and Save to Directory April 20, 2024

Most Popular Author

Most Popular Author December 14, 2023

 

Follow US:

 
 

MarcusSmall@thesmallman.com

 

TheSmallman.com - Making your small systems hum...
© Copyright 2013-2024 theSmallman.com All Rights Reserved.