i am having an excel sheet and it has multiple rows and column and if column 2 having “Tree” i want to copy all the data of that row and coy it into new sheet
I am not getting the logic in if else statement
Hi
Hope the below steps would help you resolve this
- Use a assign activity and mention like this
Dt = Dt.AsEnumerable().Where(Function(a) a(“column2 name”).ToString.Contains(“Tree”)).CopyToDatatable
This datatable will have all the records where column 2 has value as tree in it
- Now u can write this another sheet of same excel using WRITE RANGE activity
Cheers @office_work
Use Filter Data Table
Hi @office_work
Hope this help
dtTable= (From row In dt.AsEnumerable()
Where row.Field(Of String)(1) = “Tree”
Select row).CopyToDataTable()
Hi,
You can try this
FilteredDataTable = SourceDataTable.AsEnumerable().Where(Function(row) row.Field(Of String)(1) = “Tree”).CopyToDataTable()
Hi @office_work
Here’s a step-by-step guide:
-
Excel Application Scope:
- Use this activity to open your Excel file.
-
Read Range:
- Use the “Read Range” activity to read the data from the original sheet into a DataTable variable.
-
For Each Row:
- Add a “For Each Row” activity to loop through each row in the DataTable.
-
If Activity:
- Inside the “For Each Row” loop, add an “If” activity to check the value in column 2 (index 1 since indexing is 0-based in UiPath). You can use the following condition:
row.Item(1).ToString = "Tree"
- This condition checks if the value in column 2 of the current row is “Tree.”
- Inside the “For Each Row” loop, add an “If” activity to check the value in column 2 (index 1 since indexing is 0-based in UiPath). You can use the following condition:
-
Then:
- In the “Then” section of the “If” activity, add an “Add Data Row” activity to add the entire row to a new DataTable variable. Create a new DataTable variable to store the rows with “Tree.”
-
Else:
- In the “Else” section of the “If” activity, you can leave it empty as you don’t need to do anything when the condition is not met.
-
Write Range:
- After the “For Each Row” loop, use the “Write Range” activity to write the DataTable containing rows with “Tree” to a new sheet in your Excel file.
Make sure to customize the activity properties, such as Excel file path, sheet names, and DataTable variable names, according to your specific Excel file structure.
Thanks!!