Save CountRows from excel file to another excel file

Hello Guys , I’m still new with UIPath and trying to countRows in an Excel file and save the CountRows value in another excel file specific range .
I tried to use write Range but couldn’t know how to use the CountRows variable in it .
If anyone could help with it ?

Hi @Abx92 ,

Syntax: Datatable.Rows.Count

The above syntax will give you the total rows count present in your excel. You can add this into the second excel.

Thanks,
@90s_Developer

1 Like

I did this program and got the row number but how to save the row number in the 2nd file , could you pls explain step by step .
Thanks

@Abx92 ,

Do you have a separate column in the second excel file for storing the rows count value? Or you have to create a new one?

1 Like

I should save it in a specific range as in foto

@Abx92 ,

if you want to write into a specific cell, you can use the Write Cell activity for a single value, or if you have a set of values that need to be written you can use Write Range activity by specifying the range and the row count.

Thanks,
@90s_Developer

1 Like

But how to set the „Columnresult.Count.ToString“ as an input for the second excel file in write range

@Abx92 ,

try to use write cell, and mention the cell value like C5 or G10 like that and pass the row count variable.

image

1 Like

It Worked with write Cell but the process gonna be like a loop so gonna need write range

@Abx92 ,

Please refer to the below link :
Write Range (uipath.com)

For this, the input value datatype should be in Datatable.

So, u need to read the second excel and assign the value to that.

1 Like

@Abx92 ,

Follow the below steps to achieve your resultant.

1. Read the first excel (FirstExcelDT)
2. Read the second excel (SecondExcelDT)
3. Create a datarow for the second excel using assign activity
SecondExcelDatarow = SecondExcelDT.NewRow and change the datatype to Datarow by switching to the variables panel.
4. Use Assign activity and use the below syntax
SecondExcelDatarow("YourColumnName") = FirstExcelDT.Rows.Count.ToString
5. Use Add Datarow and in the datarow field use the SecondExcelDatarow variable and in the datatable field use the SecondExcelDT variable.
6. Use Write Range activity and pass the SecondExcelDT datatable variable.

Try the steps and let me know if you face any issues.

Thanks,
@90s_Developer