|
- Sub 转置()
- Dim arr, brr(), i&, maxcolumn&, k&, m&, dic As Object, s, temp() As Integer
- Set dic = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- With Sheet2
- arr = .Range("A1").CurrentRegion
- ReDim brr(1 To UBound(arr), 1 To 256)
- ReDim temp(1 To UBound(arr))
- For k = 1 To 3
- brr(1, k) = arr(1, k)
- Next
- m = 1
- For i = 2 To UBound(arr)
- s = dic(arr(i, 1) & arr(i, 2) & arr(i, 3))
- If s = Empty Then
- m = m + 1
- dic(arr(i, 1) & arr(i, 2) & arr(i, 3)) = m
- s = m
- temp(s) = 3
- For k = 1 To 3
- brr(s, k) = arr(i, k)
- Next
- End If
- temp(s) = temp(s) + 1
- brr(s, temp(s)) = arr(i, 4)
- If temp(s) > maxcolumn Then
- maxcolumn = temp(s)
- brr(1, maxcolumn) = "时间" & temp(s) - 3
- End If
- Next
- .[g1].CurrentRegion.Clear
- .[i2].Resize(m - 1, 1).NumberFormatLocal = "yyyy/m/d"
- .[j2].Resize(m - 1, maxcolumn - 3).NumberFormatLocal = "[$-x-systime]h:mm:ss AM/PM"
- With .[g1].Resize(m, maxcolumn)
- .Value = brr
- '.Sort key1:=Cells(1, 7), order1:=1, Header:=1 '按工号升序排序
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .Columns.AutoFit
- End With
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|