|
- Sub test2()
- 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")
- With reg
- .Global = False
- .Pattern = "'+|([^)]*)"
- End With
- With Worksheets("汇总")
- c = .Cells(4, .Columns.Count).End(xlToLeft).Column
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a3").Resize(r - 2, c)
- End With
- ls = c
- For i = 3 To UBound(arr)
- For j = 2 To UBound(arr, 2)
- arr(i, j) = reg.Replace(arr(i, j), Empty)
- If InStr(arr(i, j), vbLf) <> 0 Then
- If InStr(arr(i, j), "/") = 0 Then
- xm = Split(arr(i, j), vbLf)
- If Not d.exists(xm(1)) Then
- ReDim brr(1 To ls)
- brr(1) = xm(1)
- brr(j) = xm(0) & "/" & arr(i, 1)
- Else
- brr = d(xm(1))
- brr(j) = brr(j) & vbLf & xm(0) & "/" & arr(i, 1)
- End If
- d(xm(1)) = brr
- Else
- xm1 = Split(arr(i, j), vbLf)
- For x = 0 To UBound(xm1)
- If InStr(xm1(x), "/") <> 0 Then
- xm2 = Split(xm1(x), "/")
- If Not d.exists(xm2(1)) Then
- ReDim brr(1 To ls)
- brr(1) = xm2(1)
- brr(j) = xm2(0) & "/" & arr(i, 1)
- Else
- brr = d(xm2(1))
- brr(j) = brr(j) & vbLf & xm2(0) & "/" & arr(i, 1)
- End If
- d(xm2(1)) = brr
- End If
- Next
- End If
- End If
- Next
- Next
- ReDim crr(1 To d.Count, 1 To ls)
- m = 0
- For Each aa In d.keys
- brr = d(aa)
- m = m + 1
- For j = 1 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- Next
- With Worksheets("教师课程总表")
- .Cells.Clear
- Worksheets("汇总").Range("a3").Resize(2, c).Copy .Range("a3")
- .Range("a5").Resize(UBound(crr), UBound(crr, 2)) = crr
- With .Range("a3").Resize(2 + UBound(crr), UBound(crr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For j = ls To 3 Step -1
- If Len(.Cells(3, j).Value) = 0 Then
- .Cells(3, j - 1).Resize(1, 2).Merge
- End If
- Next
- .Columns(1).Resize(, UBound(crr, 2)).AutoFit
- End With
- End Sub
复制代码 |
|