|
Sub 生成教师课表()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("Sheet1")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 7 Then MsgBox "请在【基本信息设置】中设置年级名称,班级数和开始班级名称!": End
ar = .Range("a2:bd" & r)
End With
Dim br()
ReDim br(1 To 5000, 1 To UBound(ar, 2))
For j = 1 To UBound(ar, 2)
br(1, j) = ar(1, j)
br(2, j) = ar(2, j)
Next j
k = 2
For i = 3 To UBound(ar)
For j = 2 To UBound(ar, 2)
If Trim(ar(i, j)) <> "" Then
rr = Split(ar(i, j), Chr(10))
zd = rr(1)
t = d(zd)
If t = "" Then
k = k + 1
d(zd) = k
t = k
br(k, 1) = zd
End If
br(t, j) = rr(0)
End If
Next j
Next i
With Sheet2
.UsedRange.Clear
.[a1].Resize(k, UBound(br, 2)) = br
.[a1].Resize(k, UBound(br, 2)).Borders.LineStyle = 1
.[a2] = "教师姓名"
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub |
|