Invoke Code exception

Hey everyone,

I get the following exception using the invoke code.
Invoke code: Exception has been thrown by the target of an invocation.

the code I wrote inside is:
datatable.Select.ToList.ForEach(Sub(Row) Row(“Number”) = CStr(Row(“Number”)).Replace("%",""))

and the argument I passed is like following :

dt1 is the datatable I read from excel. the steps go as: read range(dt1) -> invoke code-> write range(dt1)

What I try to achieve is I want to replace “%” from the “Number” column values, meaning if its written as %5, it will be 5.

I am open to other ideas on achieving this result (without for each row).
Thank you.


You can try something like this, and copy the updated data to a new datatable and overwrite into the excel sheet.

datatable.AsEnumerable().Where(Function(row) row("Number").ToString.Replace("%", String.Empty)) .CopyToDataTable
1 Like


I get this error.

Error:" Exception has been thrown by the target of an invocation." usually happens if the column Name “Number” is not in the excel sheet.

There is a column named “Number”. I think if that was the case I wouldnt get this error.