|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim reg As New RegExp
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With reg
- .Global = False
- .Pattern = "(.+?)((?:\d+|走|分)班)"
- End With
- With Worksheets("总表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- End With
- ReDim brr(1 To UBound(arr), 1 To 2)
-
- For i = 2 To UBound(arr)
- Set mh = reg.Execute(arr(i, 1))
- If mh.Count > 0 Then
- brr(i, 1) = mh(0).SubMatches(0)
- brr(i, 2) = mh(0).SubMatches(1)
- If Not d1.exists(brr(i, 1)) Then
- Set d1(brr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- d1(brr(i, 1))(arr(i, 1)) = Empty
- End If
- Next
- For Each aa In d1.keys
- n = 10
- For Each bb In d1(aa).keys
- n = n + 1
- d1(aa)(bb) = n
- Next
- Next
- For i = 2 To UBound(arr)
- For j = 2 To UBound(arr, 2) Step 2
- If Len(arr(i, j)) <> 0 Then
- If Not d.exists(brr(i, 1)) Then
- Set d(brr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- n = d1(brr(i, 1))(arr(i, 1))
- If Not d(brr(i, 1)).exists(arr(1, j)) Then
- ls = 14 + d1(brr(i, 1)).Count
- ReDim crr(1 To ls)
- crr(3) = arr(1, j)
- crr(5) = arr(i, j + 1)
- Else
- crr = d(brr(i, 1))(arr(1, j))
- End If
- crr(n) = arr(i, j)
- d(brr(i, 1))(arr(1, j)) = crr
- End If
- Next
- Next
- For Each aa In d.keys
- ReDim drr(1 To d(aa).Count, 1 To 14 + d1(aa).Count)
- m = 0
- For Each bb In d(aa).keys
- m = m + 1
- crr = d(aa)(bb)
- For j = 1 To UBound(crr)
- drr(m, j) = crr(j)
- Next
- Next
- On Error Resume Next
- Set ws = Worksheets(aa)
- If Err Then
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- ws.Name = aa
- End If
- On Error GoTo 0
- With ws
- .Cells.Clear
- .Range("a1:j1") = Array("课程编号", "课别", "科目", "科目互斥组", "课时", "课节组合", "停课", "阶段", "自动安排场地", "年级组长及备课组长")
- .Range("k1").Resize(1, d1(aa).Count) = d1(aa).keys
- .Cells(1, 10 + d1(aa).Count + 1).Resize(1, 4) = Array("教案平齐组", "排课要求_同一天多次处理", "单双周拼合组", "统计标签")
- .Range("a2").Resize(UBound(drr), UBound(drr, 2)) = drr
- End With
- Next
-
- End Sub
复制代码 |
|