- Sub test1()
- Dim r%, i%
- Dim arr, brr
- With Worksheets("4")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- .Cells(2, c - 1).Resize(r - 1, 1).ClearContents
- .Cells(r, 2).Resize(1, c - 1).ClearContents
- arr = .Range("a1").Resize(r, c)
- For i = 2 To UBound(arr) - 1
- For j = 2 To UBound(arr, 2) - 2
- If Len(arr(i, j)) <> 0 Then
- arr(i, UBound(arr, 2) - 1) = arr(i, UBound(arr, 2) - 1) + arr(i, j)
- arr(UBound(arr), j) = arr(UBound(arr), j) + 1
- End If
- Next
- Next
- .Range("a1").Resize(r, c) = arr
- End With
- End Sub
复制代码 |