|
Option Explicit
Sub TEST2()
Dim ar, br, i&, j&, r&, k&, wks As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With Worksheets("总表")
r = .Cells(.Rows.Count, "A").End(xlUp).Row
ar = .Range("A1:K" & r).Value
For Each wks In Worksheets
If wks.Name <> .Name Then wks.Delete
Next
End With
ReDim br(1 To UBound(ar), 1 To 7) As String
For j = 1 To 6: br(1, j) = ar(1, j): Next
For j = 7 To UBound(ar, 2)
br(1, 7) = ar(1, j): r = 1
For i = 2 To UBound(ar)
If Len(Trim(ar(i, j))) Then
r = r + 1
For k = 1 To 6
br(r, k) = ar(i, k)
Next k
br(r, 7) = ar(i, j)
End If
Next i
With Worksheets.Add(after:=Worksheets(Worksheets.Count))
.Name = ar(1, j)
.[A1].Resize(r, UBound(br, 2)) = br
.Cells.EntireColumn.AutoFit
End With
Next j
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Beep
End Sub |
|