Vb.net自定义和公式不计算何时出现空白单元格

时间:2016-04-22 01:26:14

标签: vb.net excel

我有两个问题,一个是如果我有空单元格它将无法工作,第二个是它在使用sum column5时不计算表格  感谢您提供的任何帮助

Cinches正在转换一个像12' -3 1/16"到147.0625英寸  并且toNearest16th将它转换回最接近最近的十六英寸的字符串,如12' -3 1/16"  问题是当尝试使用转换求和结果时,因为如果有一个空白单元格,我会收到错误  告诉我一些爱人  再次感谢

Public Shared Function TotalSumToNearest(Nums As Object) As Object
    '----------------------------------------------------------------------
    '** Demonstrates how to use an array(or range of multiple cells) as
    '   a function argument.
    '   Can be called with formulas such as =GetArray(A1:B5), GetArray(A1),
    '   or GetArray({1,2,3;4,5,6}).
    '----------------------------------------------------------------------
    Dim Sum As Double, v As Object
    On Error GoTo Handler
    If IsArray(Nums) Then
        For Each v In Nums
            'If TypeOf v.Getvalue() Is ExcelEmpty Then

            'Else
            Sum = Sum + CDbl(CInches(v) / 12)
            'End If
        Next
    Else
        Sum = CDbl(Nums)
    End If
    TotalSumToNearest = toNearest16th(Sum * 12)
    Exit Function
Handler:
    ' GetArray = CVErr(2036)  'xlErrNum = 2036
End Function

我发布了一个工作代码,万一有人可以使用它

 Public Shared Function Sum_ToNearest_16th(Values As Object) As Object
    '----------------------------------------------------------------------
    '** Demonstrates how to use an array(or range of multiple cells) as
    '   a function argument.
    '   Can be called with formulas such as =GetArray(A1:B5), GetArray(A1),
    '   or GetArray({1,2,3;4,5,6}).
    '----------------------------------------------------------------------
    Dim Sum As Double

    If IsArray(Values) Then

        For Each ObjectValue As Object In Values
            Dim DoubleValue As Double = 0

            If TypeOf ObjectValue Is String Then
               ' Dim rst As string=""

              DoubleValue = CDbl(CInches(ObjectValue))
               ' ObjectValue=rst
            ElseIf TypeOf ObjectValue Is Double
                DoubleValue = ObjectValue
            Else
                Double.TryParse(ObjectValue.ToString(), DoubleValue)
            End If

            Sum += DoubleValue

        Next ObjectValue

    Else
        Double.TryParse(Values.ToString(), Sum)
    End If

    Return to_Nearest_16th(Sum)
End Function

0 个答案:

没有答案