How can I remove rows directly from Table1 and yet retain the formulas for Table1?
For example, If ID in Table 2 = ID in Table 1, remove that row but the formulas for other rows should be retained. Copydatatable copies the datatable as string values. So I cant use that. I want the changes to be done on Table 1 itself. Please help @Palaniyappan@Dave
I agree with @chenderson - if you have to manipulate excel itself in any significant way, then it’s much better to use a VBA macro or VBScript with UiPath’s execute macro activity
I was working on the below solution, but I was not satisfied with it.
Verify the condition in loop
Get all the index values in an array
In loop performed delete row with the index value fetched. (Here I added 2 to index to get the row position. Also reversed the array before deleting the rows, so that the rows will be deleted from bottom)
But this solution takes long time. It took around 3 hours to get the row index (file size 200K).
To delete the rows, I used “Insert/Delete row” activity in loop which saves the workbook everytime after deleting a row which ultimately increases the time
I agree, that seems like it would take too long. Why do you have the requirement that you must manipulate it within excel?
I would use linq to get the values, then I would use a for each loop on the new table to update the formulas within the datatable (would take less than 1 second), then once you are all done with the manipulation, paste everything into excel.
If you do it within excel it’s going to take a very long time if you have a significant amount of data
I don’t have anything to update here. I requirement is to remove rows that are processed from the master excel. I have the processed list in another excel. So i need to remove all those processed records from the master record.
I understand. If you have a requirement that it needs to be processed in excel, then it is going to take a very long time. I am proposing a much faster way of doing it, where everything is done within memory, then the final output is sent to excel.
In conjunction with @Dave’s response, you can always write the datatable back to Excel, and then write the original formula to the entire range next to (or in) your table in Excel at once.
@chenderson Yeah. After trying all other workaround, this is the last option I can think of. I was bit hesitant to copy the formulas as I was afraid of data error. If there is no other way, then I have to copy the excel to datatable, delete the datarows and then paste the updated datatable to original excel and finally copy the formula.
This would give you a datatable that only contains rows if ID in Table 1 is NOT in Table 2. I’ll call this dt3
Then you would use a for each row activity on dt3.
Assign dt3.item(“Num1”) = “write your formula here”
Assign dt3.item(“Num2”) = “write your formula here”
Assign dt3.item(“Total”) = “write your formula here”
After iterating through dt3, write it back into excel. For your formula, you’ll want to use the row index + 2 to (like you mentioned) so it can reference cells properly
You sure that doesn’t store the formula as a string rather than a formula? In the past, you had to use the Write Cell to place a formula.
I would normally, place the formula in the first cell with the correct relative cells for the first cell, then use a Fill Down action (ie Select Range and ctrl+d). You can also do the FillDown in VBA/vbscript.
@ClaytonM if you use Excel write range it will store it correctly as a formula. If you use workbook write range it will store as text instead of a formula