Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the length of the longest string in a column (Excel)?

Tags:

excel

vba

I have an Excel spreadsheet that I am writing out to a file. I am currently using the following method to reproduce the contents of each cell:

cell_contents = Right(Space(10) & Trim(Cells(iRow, iColumn)), 10)

However, if the contents of the cell are longer than 10 characters long (or however long I choose to specify), then I loose parts of the data. Is there a way to quickly and easily get the length of the longest string in a range of cells?

I have seen people suggest using the following loop, but I was hoping that I might be able to do it without having to loop over all the cells:

For Each c In SourceRange.Cells
   if len(c) > b then b = len(c)
Next c
like image 781
tlewis3348 Avatar asked May 15 '14 12:05

tlewis3348


People also ask

How do I find the length of a text string in Excel?

To use the function, enter =LEN(cell) in the formula bar, then press Enter on your keyboard. Multiple cells: To apply the same formula to multiple cells, enter the formula in the first cell and then drag the fill handle down (or across) the range of cells.

How do you find the maximum length in Excel?

Steps: Create a new row in “Orders” sheet above all the row headers by pressing (Ctrl, Shift and +) together and selecting Entire row from the insert dialog box. In cell Q1, right above the “Product Name” column, write the formula, =MAX(LEN(Q3:Q9995)) and hit enter.

How to find the longest string in Excel?

To find the longest string, first, find the length of each string in the array named as “states” ranging from B4 to B13. Enter the following formula in cells C4:C13. Figure2. Finding the length of each string in the column Now, enter the following formula in E4 to get the longest string in the column as a result: Figure3.

How to find the longest string in a range with criteria?

To find the longest string in a range with criteria, you can use an array formula based on INDEX, MATCH, LEN and MAX. In the example shown, the formula in F6 is: { = INDEX ( names , MATCH ( MAX ( LEN ( names ) * ( class = F5 )), LEN ( names ) * (...

How to calculate the length of a text in Excel?

In simple words, LENGTH Function is used to calculate the length of a text in an excel cell. LEN formula in excel has only one compulsory parameter, i.e., text. text: it is the text for which to calculate the length.

How to find shortest and longest string from a column in MySQL?

SQL Query to Find Shortest & Longest String From a Column of a Table 1 Creating a Database : 2 Using Database : 3 Table Definition: 4 Adding Data to Table: Now let’s find the shortest and longest firstName from the table we have just created using char_length (), min (), and max () functions and LIMIT ... 5 The shortest firstName : More items...


1 Answers

Could just use ... {=MAX(LEN(A2:A200))}

In the top cell put =MAX(LEN(A2:A200)) .. and then press CTRL-SHIFT-ENTER to get the curly braces.

like image 157
Sim2K Avatar answered Oct 11 '22 14:10

Sim2K