Sub test()
Dim r As Range, x, y, z
Application.ScreenUpdating = False
z = Range("b65536").End(xlUp).Row
Range("a1:a" & z).Copy [c1]
For Each r In Range("a1:a" & z)
'如果r是合并单元格,且r地址等于r所在合并区域的首个单元格地址
If r <> "" Or r.MergeCells And r.Address = r.MergeArea.Cells(1).Address Then
x = r.MergeArea.Row
y = x + r.MergeArea.Count - 1
Cells(x, 3) = Application.Sum(Range(Cells(x, 2), Cells(y, 2)))
End If
Next r
With Range("c1:c" & z)
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End Sub
试验3.rar
(17.36 KB, 下载次数: 18)