Update excell value

Hi @Ellen ,

Although the solution above with invoke code will work, I don’t think it’s the best method for newcomers, as using Invoke code when you can do the same with UiPath Activities, might be misleading for new developers starting in UiPath.

Another variant from the solution provided in the 1st answer would be:

  1. Save Excel as Datatable (Using Read Range Workbook, as you don’t need formatting)

  2. Find the rows you want to edit.

2.1 - Using LINQ - (Faster but more complex) → dt.AsEnumerable.Where(Function(x) CInt(x("CaseID").ToString.Trim) = 12 OrElse CInt(x("CaseID").ToString.Trim) = 25).AsDataview.ToTable

  • This will keep the rows with ID 12 and 25 in a separate DT, that you can then iterate, and find the index on the original DT. Therefore you are only iterating the number of desired rows, not all of them.
  • You will need to use IndexOf (LINQ - Search data table and return row index) to find the rows on the original DT and update them as explained in 2.2.

2.2 - Using ForEach Row in Datatable Activity - inside the For Each, have an IF, with the following condition (99% similar to post #1) CInt(CurrentRow("CaseID")) = 12 OrElse CInt(CurrentRow("CaseID")) = 25
If True, then use 2x assigns to update the values of Status and Date as follows:

  • CurrentRow("Status") = "Updated"
  • CurrentRow("Date") = Now.ToString("MM/dd/yyyy")
  1. As we have edited the DT, not the Excel, remember to rewrite it, so you get the updated values back in your excel.

Again, both solutions above will work, they are just different in terms of complexity, and ease of understanding. Try to find the best for you :slight_smile:

BR,
Ignasi

1 Like