How to get last Row from specific Excel column

Hello,

I am trying to get last used row for specific column from Excel file. for me it is giving output as per entire data table last row.

As per my current Code it is giving me output as 9 as per A Column data. But I want to update Status in B Column after each transaction of A Column, So want to get last Used Row from B Column only.

Hi @nilesh.mahajan

You can make use of REframework with Datarows and then just update the transaction item in set transaction state. This would be more efficient.

Else
Read the excel to a datatable, using read range/ read range workbook
Use for each row in datatable activity
and update the CurrentRow(“Status”) = “Printed” // Any conditions using if

and finally write back the datatable to excel, using write range workbook

Do mark it as solution if it helps :innocent: !

Hi @nilesh.mahajan

Try this,
lastUsedRow_B = dt_Input.AsEnumerable().Where(Function(row) Not String.IsNullOrWhiteSpace(row(“B”).ToString)).Count

Update this as per your dt & columns.This counts only the non-empty rows in column B of your DataTable and gives the correct last used row based on that column.

If helpful, mark as solution. Happy automation with UiPath

Hello,
Thanks for giving solution.
I have tried with this logic, but it gives me output as 1. ideally it should give 3, because 2nd is Last used row in B Column.

Tried below.
Input_DT.AsEnumerable().Where(Function(row) Not String.IsNullOrWhiteSpace(row(“Status”).ToString)).Count

@nilesh.mahajan

Can you try this,

Input_DT.AsEnumerable().
Where(Function(row) Not String.IsNullOrWhiteSpace(row(“Status”).ToString)).
Select(Function(row) Input_DT.Rows.IndexOf(row)).
DefaultIfEmpty(-1).
Max()

OR

Input_DT.AsEnumerable().
Where(Function(row) Not String.IsNullOrWhiteSpace(row(“B”).ToString)).
Select(Function(row) Input_DT.Rows.IndexOf(row)).
Max() + 1

@nilesh.mahajan

You can also use inbuilt excel activity Find first/last row data row

and you can use it as num+1 to get next cell and use one

Hope this helps!

@nilesh.mahajan,

Follow this solution

Input file:

Code:

Output:

Hello Ashok,
Congratulations for MVP award & Trophy…

Thanks for Suggestion. But I am not able to find Excel Process scope in my activities. even in Manage Packages also not able to get.
Can you please guide me on this.

Thanks a lot @nilesh.mahajan! :heart_eyes:

Install the UiPath.Excel.Activities package and check the activities filter you selected all the options like this:

Hi @nilesh.mahajan

Use
LastRow = Input_DT.AsEnumerable().Reverse().FirstOrDefault(Function(row) Not String.IsNullOrWhiteSpace(row(“Status”).ToString()))

LastRowIndex = If(LastRow IsNot Nothing, (Input_DT.Rows.IndexOf(LastRow) + 1).ToString(), “0”)

If helpful, mark as solution. Happy automation with UiPath

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