本帖最后由 zhaogang1960 于 2014-12-9 20:39 编辑
4楼代码假设编号最大为11,下面去掉该条件- Sub 编号未知()
- Dim arr, brr(), d As Object, i&, j&, m&, c&, s$
- Set d = CreateObject("scripting.dictionary")
- arr = Sheets("Sheet1").Range("A1").CurrentRegion
- c = Application.Max(Sheets("Sheet1").[a:a])
- ReDim brr(1 To UBound(arr), -3 To c)
- For i = 2 To UBound(arr)
- s = arr(i, 2) & arr(i, 3)
- If Not d.Exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, -3) = m
- For j = 2 To 4
- brr(m, j - 4) = arr(i, j)
- Next
- brr(m, arr(i, 1)) = arr(i, 4)
- Else
- brr(d(s), 0) = brr(d(s), 0) + arr(i, 4)
- brr(d(s), arr(i, 1)) = brr(d(s), arr(i, 1)) + arr(i, 4)
- End If
- Next
- With Sheets("Sheet2")
- .Cells.ClearContents
- .[a1:d1] = Array("编号", "班组", "姓名", "合计")
- .[e1] = 1
- .[e1].AutoFill Destination:=.[e1].Resize(, c), Type:=xlFillSeries
- .[a2].Resize(m, c + 4) = brr
- End With
- End Sub
复制代码
|