Extracting cell value having maximum character in a column of a table

Hi All,

I want to extract the value of the cell in below Description column with maximum characters

For e.g. in below Excel table I want to get Description (mnopqrstyuvvvvvvvvvv abcdeeded pqrst) as my output variable value. If anyone can help??

Excel table

Hi ,

The input is in excel so the new column can be used to take the count of each row and take max of value using linq .

Can you plz help with the same?

HI ,

391125.xlsx (14.9 KB)
391125.xaml (8.1 KB)

Read Range into a datatable

For Each Row in Datatable

  • if index is 0
    – Then assign longestDescription = row.Item(“Description”).ToString
  • Else
    – If row.Item(“Description”).ToString.Length > row(index-1).Item(“Description”).ToString.Length
    — Then assign longestDescription = row.Item(“Description”).ToString

Basically it loops through and compares each row to the previous row. If the current row is longer, it stores the current row value, otherwise it keeps the existing value since it’s longer or the same length. Logically the result will be that after it loops through all rows the longestDescription variable will contain the longest value. You might want to consider altering the logic as necessary to account for what happens if there are two rows that have the same length and are the longest. The code I gave you will store the first of those two values.