I would like to use Excel “Remove Duplicates” function to delete the duplicated records in my worksheet. In excel, I can enter the following keys (in Excel) to perform this operation :
Alt + a
m
tab
tab
enter
Then, i tried to add 5 “Send Hotkey” activities in uiPath according to the list as above. However, when it run into step 2, the robot type a “M” into cell A1 instead of trigger the “Remove Duplicates” window.
first use Read Range activity to read the Excel file and it will give you output as data table.
2)Required dataTable = dataTablename.DefaultView.ToTable(true, “Column1”,“Column2”,…).CopyToDataTable
Where:
First parameter in ToTable() is a boolean which indicates whether you want distinct rows or not.
Second parameter in the ToTable() is the column name based on which we have to select distinct rows.
Only these columns will be in the returned datatable.
Your approach is good… But, when working with UiPath, you cannot edit a excel sheet in a Excel Application Scope activity. So, even though you were able to remove duplicates using the hot key method, it will not get saved. So the best option would be to follow these steps.
use a Read Range activity to read the data into a datatable
Use the datatable activity Remove Duplicate Rows to remove all the duplicate rows from the datatable
Use a Write Range activity to write the data back into the same excel. Write Range activity will overwrite the existing data, so you will finally have the modified dataset without duplicates.
In fact, I cannot use data table approach because when I paste the content, the leading zero will be removed and the value become Number (e.g. read range with value ‘00001’ and the cell become 1 after using write range. For details, you may refer to this question I posted before.