How to sum all values in a column of an excel/Datatable?

Hi there @yogeshgyw,
Please try the following:
dtTesting.AsEnumerable.Sum(Function (x) If(Double.TryParse(x.item("Column2").ToString, Nothing), Double.Parse(x.Item("Column2").ToString), 0))

This will convert the DT to an enumerable, then SUM the column value (as a double) if it is valid, otherwise it will simply add 0.

You will need to change the references for the DataTable (dtTesting) and columns (“Column2”).

Apologies for the delay, please let me know if it works!

Thanks,
Josh

15 Likes