Get the index of a particular value in a data table

How can I get the index of a particular value on a certain column? Column name “Status”

1 Like

With expression like this
Int_columnindex = Yourdatatablename.Column.Indexof(“yourcolumnname”)
Where int_columnindex is a int32 variable

Cheers @rohangroombridge

Hi, Thank you for looking into this. May I ask how your syntax get a particular value from that column?

Eg:
Status
Row1
Row2
Row3

How do I get the index of Row3…?

1 Like

@rohangroombridge

  1. use Read Range activity to read the data from excel file and will give you output as DataTable and say ‘DT’.

  2. And then use ForEach Row activity to iterate that DataTable.

    ForEach row in DT
        Int index = DT.Rows.IndexOf(row)+2
        If row("Status").Tostring.Equals("requiredValue")
       Then print index value.
    
1 Like

In that case
Use a for each row loop and pass the datatable variable as input
—inside the loop use a writeline with this expression
Yourdatatablename.Rows.Indexof(row)

This will give us the row index
While the previous comment mentioned expression will give us the column index

Cheers @rohangroombridge

Thank you. What if I need to start at a particular row?

Example workflow:
Read range excel spreadsheet (output = DT)
The DT Will look like this:
Column name: “Status”
Row1 = “Completed”
Row2 = “Completed”
Row3 = “Completed”
Row4 = “Completed”
Row5 = “In Completed”
Row6 = “In Completed”
Row7 = “In Completed”
Row8 = “In Completed”

I need to have the for loop dynamically start from the for row with a value of “In Completed”. The “In Completed” value index’s will change everytime new data is loaded into the spreadsheet so I need a way for the for loop to start looping at the first row of the index of the row containing the “In Completed” value

How do I do that?

if you want to process only “In Completed” records, use if condition → row(“status”)=“In Completed”

Then proceed.

Or

use Filter datatable activity to filter “In Completed” records alone then loop through.

Thanks!

Thank you for replying. Just to clarify to everyone. Every loop I am doing I want to replace the cell value from “In Completed” to completed. I’m not sure a filter activity will do this because won’t it filter what I need and then I don’t think it will write to the same cell index back into my spreadsheet will it?

Have a look at either:

UiPath.Core.Activities.LookupDataTable
Official doco here - Lookup Data Table

UiPath.Core.Activities.FilterDataTable
Official doco here - https://docs.uipath.com/activities/docs/filter-data-table
With this you can remove the data row based on a filter and with another command write a new line at the end to replace it. Later, sort the DT if the order matters.

This may not offer your full solution but will possibly help

Hey palaniyappan I want to add a value at a specific cell but my row is empty and I want to only write a value like Failed pr Success under a Column

Hi @Kunal_Kumar

Row empty means the value at a cell is empty ?