Error Help: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class

Hi there,

I am hoping to get some guidance. I am trying to sum a column called “Value” in Excel, only the numeric values. I read the file as DT but when I wrote the following code in Write Cell function:

“DT.AsEnumerable.Sum(Function(x) If(IsNumeric(x(“Value”).ToString.Trim),CDbl(x(“Value”).ToString.Trim),0)).ToString”

It gives the following error. I appreciate if someone offer assistance. thanks.

Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

It’s complaining about the IsNumeric() function. To get it to work use either Information.IsNumeric() or myString.IsNumeric().

DT.AsEnumerable.Sum(Function(x) If(Information.IsNumeric(x("Value").ToString.Trim),CDbl(x("Value").ToString.Trim),0)).ToString

Or

DT.AsEnumerable.Sum(Function(x) If(x("Value").ToString.Trim.IsNumeric,CDbl(x("Value").ToString.Trim),0)).ToString

@ptrobot

Many thanks. Your suggestion works perfect. You saved me at least a day. Cheers.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.