How to filter excel sheet through if condition

Hi, I want to filter age from excel sheet (condition is filter age between 30 to 40) and write that filtered item into a new sheet through if condition.

@Lakshya_Garg

Welcome to forums

Build a Datatable using Build Datatable activity and create a variable as let say DT1
Use Read Range activity to read the excel sheet and create a variable in properties which will output a Datatable Lets say Dt2

Now use For Each row activity and give the variable of the Datatable DT2

Now inside the For Each row activity place If condition and write as below

Cint(Row(“Age”).ToString) >=30 and Cint(Row(“Age”).ToString) <=40

In then you can use Add row activity of DT1

Also you can replace with one expression also

Hope this will help you

Thanks

Hi,

Using read range activity to store your excel data into data table.

Use filter data table activity to filter the age in the data table and get the output as filter data table.

Use write range activity to store the data into different sheet.

https://docs.uipath.com/activities/docs/filter-data-table

@Lakshya_Garg

Also you can refer to my post which is marked as solution with the same case

Hope this will help you

Thanks

Hi @Lakshya_Garg

Refer the link

Regards
Gokul

can I filter data without build datatable

@Lakshya_Garg

Yes, you can do with that also

As you asked using IF condition, so I provided the solution

Also you can just filter that using assign activity itself

Use Read Range and Create Datatable variable let’s say Dt1

Now use Assign activity and write as below

Dt1 = dt1.Select("[age] >= 30 AND [age] <= 40 ").CopyToDataTable

This also will filter and store the result in Dt1

Hope this will help you

Thanks

@Lakshya_Garg

We can do that also using the Assign activity again

Use Read Range and create a Datatable Dt1

Now use Assign activity and create a datatable variable let’s say DtTemp

Assign actvity write as DtTemp = Dt1.Clone()

Now in Add Datarow activity you can use DtTemp

Hope this will help you

Thanks

Thanks

can you tell me onemore thing

please tell me the meaning of this .

(dt2.Rows.Count+2).ToString
why we write count +2 here

@Lakshya_Garg

If our goal is to write back to the excel then we need to add +2

because the Rows Index starts with 0 and in excel starts with 1, and there was a header so to write the data after the header then we need to make +2

If your excel don’t have the header then we need +1 only

Hope this helps you

Mark as solution, so that others will also benefit from this

Thanks

I want to Color only where I have value not full column in excel how do i do that through set range color

Employees300.xlsx (46.2 KB)
If we see the color of column the color is spread in full column but i want color only where i ahve data.

@Lakshya_Garg

I suggest to post in new thread, because this is a new topic all together
So close this thread by marking solution and maintain another post
This will help others not in confusion

Thanks

1 Like