Finding row count

Hi there is an Excel which contain data(using read range I had store data in datatable).

In datatable I need to find keyword “TOTAL”.

If “Total” found in data table I need row count(means in which row “Total” is present I need that row number or row count)

Need ur Help!!

Regards.

@Addy_619

in general you have two approaches:

  • using for each row analyzing the columns and do using the inbuilt index functionality to get the position (index) of the row
  • doit with a linq statement

in case of you need more help, can you provide some sample data?

linq statement?

LINQ let us allow to formulate e.g. searches on Objects, Collections, DataTables and more

However your task is even solveable with the plain activities provided by UiPath

For each row, if activity …

@ppr using plain activities if u give example it will be more helpful

Regards.

@Addy_619
sure but please give some sample or demo data so we are closer to your scenario

@ppr,

Give me 5 minutes i will provide you the solution.

@Ankumarm
please provide it to @Addy_619 he does need it

Thanks @Ankumarm

@addy_619 to solve without linq, do the following:

  1. read range for the entire excel sheet → save as dt1
  2. For each row activity (on dt1)
  3. If row.item(“YourColumnName”).ToString.ToUpper.Contains(“TOTAL”)
    a. (true side) Assign TotalRow (this is an int32 variable) = dt1.indexof(row) + 1
    b. Break activity
    c. (false side) leave this blank

Now your integer variable called TotalRow is the row number within excel that contains the word “TOTAL” in the column you’re searching. If TotalRow = 0, then that means the word “TOTAL” was not found.

Hi,

this is the method I usually use in .net linq

arrRows = dt1.AsEnumerable.Where(Function(r) String.Join("",r.ItemArray).ToUpper.Contains("TOTAL") ).ToArray
If arrRows.Count > 0
    rowNumber = dt1.Rows.IndexOf(arrRows(0))+1

So, use linq to find the row where it contains the word “Total”. ItemArray translates the entire row into an array of strings basically. Then, check to see if you found a match checking its count. Then, use IndexOf to find the index of the matched row. Add 1 for the row number.

Hopefully, that helps.

Regards.

1 Like

FindingRowCount.zip (11.4 KB)

Please find the attached workflow.

Please like and mark this as resolved… if it mets your requirement.

Thanks,
Anil

2 Likes

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