How to sort in Excel - alphabetical order

Hi

I need some help to sort a datatable where the countries (column: “Land”) are sorted in alphabetical order, in UiPath.

Column A: “Areal” is how big the land - square meter.
Column B: “Land” is the name of the land.

So how can I sort this table, see picture below?

1 Like

@Mariafig
Give a try on DatatableVar.AsEnumerable.OrderBy(function (row) row(“Land”).toString.trim).CopyToDatatable

Use this Statement in an assign Activity and feel free to assign IT to a new or your Origin datatable

2 Likes

Thanks!

I tried, but I have some problems with the Variable Type. I’m not very good to manipulation variables:crazy_face:

@Mariafig
I will Help you in a few mins, can you Share your xaml with me

1 Like

@Mariafig
I have sent you an modified file by message. Once I have done with my dinner I will give you a feedback on the edit. However can you check the new file in the meanwhile?

1 Like

@Mariafig

On the read range the uutput was not configured, so I assigned to a Variable: dtData
You can rename as you want

Following Assign Activity is doing the Sorting of the entire DataTable
Done with statement from above

in the for each row activity I logged out for demo purpose the country
grafik

Kindly note: there is 1 row with blank country name

Let us know your open questions in case there are. Feel free to flag the solution when it is working, so others from the forum can benefit from this.

1 Like

Hi
You were almost done
May be these steps in sequence would help you resolve this
—use Excel application scope and pass the file path of the excel as input
—inside the scope use a READ range activity and get the output with a variable of type datatable named dt
—followed by this use a assign activity like this
dt = dt.AsEnumerable().Orderby(Function(a) a.Field(of string)(“Land”).ToString).CopyToDatatable()

So the ordered column will be now copied back to the datatable and we don’t need to use a for each row loop at all

Or even we got a better option @Mariafig
SORT DATATABLE ACTIVITY can be directly used once after using read range activity
Where mention the input as dt and output as again dt and mention the column index as 1 with sort as ascending or descending so that it will get sorted

@Mariafig As column index usually starts from 0 for the columns in a datatable

Kindly try this and let know for any queries or clarification
Cheers

2 Likes

Thank you! :slight_smile:

1 Like

Thank you very mutch, it worked :slight_smile:

Now I have to get the “Areal” as well, because the “Areal” is relatated to the “Land”. But I think I can manage is with Look Up Data Table activity.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.