How to get the last row index of a Specific column in a DT?

Hello Forum,

Today I’m working with Data Tables extracted from Google Sheets. And I have a table full of columns which info is fully independent from each other. What I mean with that is that when I input a value to the table It’s just for one column.

I need to find the last row of a specific column in a data table? Which method or activity can I use?

Let me know if you understood the quest.
Thank you very much for your attention

Hi @Luis_Fernando

Correct me if I’m wrong you need to find the last row of the sheet that you read right?

After reading you will get the datatable right

That (Datatable.rows.count+1).ToString will get you the last row as per the sheet so that you can append data from there if you are appending

Regards
Sudharsan

I think you didn’t quite get it.

I have this table that stores payments date and amounts of specific types of expenses.
Every time a expense o any of this columns type is made the obot should find the column of the expense and type the date and amount of the current expense in the correct row of the column. So I need to find the last row index of a specifc column.

You could loop through each row, check if your column is null or empty with String.IsNullOrEmpty(yourRow(“YourColumn”).ToString), and if false use the index from the for loop - 1 as your row number.

1 Like

Yeah that’s a opcion I thought of, but I think there might be a lighter way to achieve it. As simple as when we want to find the last row of the data table. ex: datatable.Rows.Count

Don’t you think?

@Luis_Fernando you can use for each row as @LeviGraff suggested and once you reach empty or null value in the specific column that you are looping through put the Break activity after saving the index number.

Another way is to try something like this:
dtDataTable.Select("'ColumnName' <> '').Count
assuming there are no blank values in the middle of the column

@Luis_Fernando please let me know if that works and if so, kindly please mark this as the solution :wink:

Regards,
Kamil

2 Likes

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