How can I get the row index in Excel

Hello, I’m a beginner and I don’t know how can I get the row index in Excel and for use it as a variable. Can someone explain this to me in detail? I’m working on UiPath StudioX.
Thank You very much :slight_smile:

1 Like

Hi @sullivanne

If you want to find position of the certain value in the excel. Try this:

Excel Application Scope (to open the Excel file)
  Read Range (to read data into a DataTable)
For Each Row (in DataTable)
  If (row("Column1").ToString = "ValueToFind")
    Assign: RowIndex = row.Index

or
Use Vlookup activity to find the position of the value
https://docs.uipath.com/activities/other/latest/productivity/v-lookup-x

1 Like

I would like to share some video reference instead of code here as you are new and will help u to understand better

Refer this video for how to access excel file in studioX and for many other scenarios

To get the row index of a datatable refer this video

Hope this helps

Cheers @sullivanne

1 Like


Unfortunately, it doesn’t show me a specific index. Did I do something wrong?

Let us know for any further clarification

Cheers @sullivanne

1 Like

@sullivanne

you need to use log message below the set variable

and pass the value as rowindex

@sullivanne

I wrote a sample for you ,so you can compare it with your code.
Or you can upload your code so I can check it.
ExpenseDeclaration.xlsx (9.0 KB)

Main.xaml (6.9 KB)

Hello, I changed the project, but it shows me the index one less, instead of 5 it shows me 4… Do you have any idea what I did wrong?

@sullivanne

Index starts with zero and row numbering starts with 1. If you want the row number then add +1 to the output.

1 Like

dkll scdvl cdfsllo[pqod ddfc l dqlddwpdox msmd doons dwjod n xncsde fj jx cs dwcsdcss

1 Like

try this

For Each Row in DataTable

Assign : item("RowIndex") = DataTable.Rows.IndexOf(item) + 1

1 Like

Hello, thank You, but I have error - do You know what I’m doing wrong?

image

Hi @sullivanne

(Read_Range_DT.Rows.IndexOf(item) + 1).ToString

@sullivanne
DT.Rows.IndexOf(item) + 1