Kavyasri
(Kavya)
September 11, 2020, 7:09am
1
Hi everyone,
I have one doubt regarding deleting rows containing blank spaces.I tried one process but I took 2 different sheets(one is blank) so that the output comes in the 2nd blank sheet…But I want the output to be present in the same sheet.This is the workflow which I tried.
usecase3.zip (2.5 KB)
Input:
Expected Output :
Can anyone please suggest me any idea so that the result should come in the same sheet…
Thanks & Regards.
Yoichi
(Yoichi)
September 11, 2020, 7:36am
2
Hi,
I think it should be easier to use LINQ Where method. Can you try the following?
testdt2 = testdt.AsEnumerable.Where(Function(r) r("Department") IsNot Nothing AndAlso (not String.IsNullOrWhiteSpace(r("Department").ToString))).CopyToDataTable
Main.xaml (8.3 KB)
Note: Your workflow lacked DataSetExtensions reference due to UiPath problem. I modified it in above Main.xaml.
Regards,
1 Like
ImPratham45
(Prathamesh Patil)
September 11, 2020, 7:38am
3
Hi U can use below VBA code and use it in workflow - use Invoke VBA
Sub Delete_Rows_Based_On_Value()
Dim ws As Worksheet
'Set reference to the sheet in the workbook.
Set ws = ThisWorkbook.Worksheets(“Sheet1”)
ws.Activate
'Clear any existing filters
On Error Resume Next
ws.ShowAllData
On Error GoTo 0
'1. Apply Filter
ws.Range(“A1:B1000”).AutoFilter Field:=2, Criteria1:=“”
'2. Delete Rows
Application.DisplayAlerts = False
ws.Range(“A1:B1000”).SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True
'3. Clear Filter
On Error Resume Next
ws.ShowAllData
On Error GoTo 0
End Sub
Here u found ur xaml
usecase3.zip (9.1 KB)
1 Like
Hi,
Keep it simple, filter the data using a LINQ select:
(From Row In dtTable.Select() where Not String.IsNullOrEmpty(Row.Item(“Department”).ToString)select Row).CopyToDataTable
Full description:
Read range - get the Excel data in a datatable
Filter the datatable with the above LINQ select
Delete Range - clear data in Excel (you need to clear the data, otherwise there is a risk to have more rows than expected)
Write range - put the filtered data back in Excel
Here’s a picture of the flow:
Hope this helps,
Cristian
1 Like
Kavyasri
(Kavya)
September 11, 2020, 7:59am
5
Hi @Yoichi , I cannot see code in the workflow…Activity is missing
Kavyasri
(Kavya)
September 11, 2020, 8:14am
6
@Cristian_Bardas Thanks for the reply…I am getting this error in the Linq select statement
Yoichi
(Yoichi)
September 11, 2020, 8:14am
7
Hi,
Did you open the xaml file from download folder?
If so, can you try to move the above Main.xaml to your original project folder? (if necessary, please rename it before move.)
Regards,
1 Like
Kavyasri
(Kavya)
September 11, 2020, 8:15am
8
Thanks for the help @ImPratham45 …I am not familiar with VB but I will try this
You need to make sure you have imported the following namespaces, sometimes UIPath forgets about them …
System.Data.DataSetExtensions
System.Linq
System.Linq.Expressions
After you have imported them, if you still get an error, save your workflow, close and reopen, the error will be gone.