Sub 提取()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim i As Long, r As Long, rs As Long
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("全部班级")
rs = .Cells(Rows.Count, 4).End(xlUp).Row
ys = .Cells(4, Columns.Count).End(xlToLeft).Column + 1
br = .Range(.Cells(4, 2), .Cells(rs, ys))
End With
With Sheets("班级学科汇总")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(1, Columns.Count).End(xlToLeft).Column
If r > 1 Then .Range(.Cells(2, 1), .Cells(r, y)).Borders.LineStyle = 0: .Range(.Cells(2, 1), .Cells(r, y)) = ""
ar = .Range(.Cells(1, 1), .Cells(rs, y))
For j = 2 To UBound(ar, 2)
d(ar(1, j)) = j
Next j
k = 1
For j = 5 To UBound(br, 2)
If br(1, j) = "" Then br(1, j) = br(1, j - 1)
t = d(br(1, j))
If t = "" Then
k = k + 1
d(br(1, j)) = k
t = k
ar(k, 1) = br(1, j)
End If
For i = 3 To UBound(br)
If Trim(br(i, j)) <> "" Then
If InStr(br(i, j), Chr(10)) > 0 Then
km = Split(br(i, j), Chr(10))(0)
xm = Split(br(i, j), Chr(10))(1)
lh = d(km)
If lh <> "" Then
ar(t, lh) = xm
End If
End If
End If
Next i
Next j
.[a1].Resize(k, UBound(ar, 2)) = ar
.[a1].Resize(k, UBound(ar, 2)).Borders.LineStyle = 1
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|