Option Explicit
Sub abc()
Dim a, i, j, k, m
a = Sheets("汇总").[a1].CurrentRegion.Offset(2).Value
If (UBound(a, 2) - 2 - 1) Mod 4 Then MsgBox "!": Exit Sub
Call doevent(False)
For Each i In Sheets
If i.Name <> "汇总" Then i.Delete
Next
For i = 1 To UBound(a) - 2
a(i, UBound(a, 2) - 1) = Replace(a(i, UBound(a, 2) - 1), "]", ")")
a(i, UBound(a, 2) - 1) = Replace(a(i, UBound(a, 2) - 1), "[", "(")
a(i, UBound(a, 2) - 1) = LCase(a(i, UBound(a, 2) - 1))
Next
Call qsort(a, 1, UBound(a) - 2, 1, UBound(a, 2), UBound(a, 2) - 1)
ReDim b(UBound(a), 5)
j = Split("序号,名称,开始时间,作业时间,作业内容,周期", ",")
For i = 0 To UBound(j)
b(0, i) = j(i)
Next
For i = 1 To UBound(a, 1) - 2
If Len(a(i, UBound(a, 2) - 1)) Then
For j = 2 To UBound(a, 2) - 2 Step 4
If Len(a(i, j)) Then
m = m + 1
b(m, 0) = m: b(m, 1) = a(i, UBound(a, 2) - 1)
For k = j To j + 3
b(m, k - j + 2) = a(i, k)
Next
End If
Next
If a(i, UBound(a, 2) - 1) <> a(i + 1, UBound(a, 2) - 1) Then
Sheets.Add
With ActiveSheet
.Name = a(i, UBound(a, 2) - 1)
.[c:d].NumberFormatLocal = "yyyy.mm.dd"
With .[a1].Resize(m + 1, 6)
.Borders.LineStyle = xlContinuous
.Value = b
End With
.Columns(1).Resize(, 6).AutoFit
End With
m = 0
End If
End If
Next
Call doevent(True)
End Sub
Function doevent(flag As Boolean)
With Application
.DisplayAlerts = flag
.ScreenUpdating = flag
End With
End Function
Function qsort(a, first, last, left, right, key)
Dim i As Long, j As Long, k As Long, x, t
i = first: j = last: x = a((first + last) \ 2, key)
While i <= j
While a(i, key) < x: i = i + 1: Wend
While x < a(j, key): j = j - 1: Wend
If i <= j Then
For k = left To right
t = a(i, k): a(i, k) = a(j, k): a(j, k) = t
Next
i = i + 1: j = j - 1
End If
Wend
If first < j Then qsort a, first, j, left, right, key
If i < last Then qsort a, i, last, left, right, key
End Function