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 ,

PFA.
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.

1 Like

Hi, I’ve written the logic for the same but getting below issue. If you can help?

image

Attaching workflow for same:

Sequence3.xaml (9.9 KB)
391125.xlsx (14.9 KB)

I would be really grateful if you can help on same.

Can you please make it more understandable? Also, I am getting below issue while actually running the code:

image

row(Index-1).Item is incorrect

It is row.Item(Index-1) and for your purposes you need the length so it is row.Item(index-1).ToString.Length

The index is a property of Item not a property of Row.

1 Like

Hey!
Could you please help with the expression for if??
row.Item(“Description”).ToString.Length > row.Item(index-1).Item(“Description”).ToString.Length

this is coming as wrong? Please help>

row.Item(“Description”).ToString.Length > row.Item(index-1)(“Description”).ToString.Length

Hey!

It’s giving below issue
image

.xaml file for your reference:

Sequence3 (1).xaml (11.9 KB)

row.Item(“Description”).ToString.Length > row(index-1)(“Description”).ToString.Length

Hello,

Please change the if condition to this:
row(“Description”).ToString.Length > errorDescription.Length

Thanks!
Athira