Sub 合并单元格自动求和()
Application.ScreenUpdating = False
j = Range("F" & Rows.Count).End(3).Row
Range("G3:G" & j).UnMerge
Range("G3:G" & j).ClearContents
n = Range("F3")
m = 3
For i = 4 To j
If Range("B" & i) = "" Then
n = n + Range("F" & i)
Else
Range("G" & i - 1) = IIf(n = 0, "", n)
If m < i - 1 Then Range("G" & m & ":G" & i - 1).Merge
n = Range("F" & i)
m = i
End If
Next
Range("G" & i - 1) = IIf(n = 0, "", n)
If m < i - 1 Then Range("G" & m & ":G" & i - 1).Merge
Application.ScreenUpdating = True
End Sub
EXCEL vba实现合并单元格自动求和,利用B列可以情况在G列实现。有空附上代码
=SUM(F3:F12)-SUM(G4:G12)
试试看
看了一下你的合并单元格是从第4行开始的
=SUM(F4:F12)-SUM(G5:G12)