- Sub 求和()
- Dim arr, brr, i, j, r, n
- With Sheet1
- r = .Cells(Rows.Count, 2).End(xlUp).Row
- c = .Cells(1, Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- End With
- For i = 2 To r
- For j = i + 1 To r + 1
- If j <= r Then
- If arr(j, 1) = "" Then
- arr(j, 1) = arr(i, 1)
- End If
- If arr(i, 1) <> arr(j, 1) Then
- arr(i, 5) = Application.Sum(Range(Cells(i, 3), Cells(j - 1, 4)))
- i = j
- End If
- arr(i, 5) = Application.Sum(Range(Cells(i, 3), Cells(j - 1, 4)))
- End If
- Next
- Next
- Sheet1.Range("e1").Resize(r) = Application.Index(arr, 0, 5)
- End Sub
复制代码 |