汇总合并单元格下的项目

时间:2015-05-27 11:48:47

标签: excel excel-vba sum cells vba

我想请求帮助来合并合并单元格下的所有项目。 项目如下所示:

       June  
0 1 2 3 4 5 6 7 8 9  
2 3 4 5 6 7 8 9 0 1

六月是一个合并的单元格,我想要汇总其下的所有项目。 这甚至可能吗?

1 个答案:

答案 0 :(得分:1)

无论单元格是合并还是未合并,这都将起作用。假设我们已将 A1 C2 合并为以下内容:

enter image description here

以下 UDF()将给出数值的总和:

Public Function InternalSum(rin As Range) As Double
   Dim v As String, CH As String, temp As String
   Dim dot As String, L As Long, i As Long
   Dim capture As Boolean
   v = rin(1).Text
   InternalSum = 0
   dot = "."
   temp = ""
   capture = False
   L = Len(v)
   If L = 0 Then Exit Function
   For i = 1 To L
      CH = Mid(v, i, 1)
      If IsNumeric(CH) Or CH = dot Then
         capture = True
         temp = temp & CH
         If i = L Then
            InternalSum = InternalSum + CDbl(temp)
         End If
      Else
         If capture Then
            capture = False
            InternalSum = InternalSum + CDbl(temp)
            temp = ""
         End If
      End If
   Next i
End Function

enter image description here

请注意:

=internalsum(A1)

=internalsum(A1:C2)

会奏效。