|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 生成课程总表()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim ar As Variant, br As Variant, cr As Variant, arr As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("汇总")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(4, Columns.Count).End(xlToLeft).Column
If r < 5 Or y < 5 Then MsgBox "汇总为空!": End
ar = .Range(.Cells(3, 1), .Cells(r, y))
End With
With Sheets("教师名册")
rs = .Cells(Rows.Count, 2).End(xlUp).Row
If rs < 2 Then MsgBox "教师名册为空!": End
br = .Range("b2:b" & rs)
End With
With Sheets("课程清单")
ws = .Cells(Rows.Count, 1).End(xlUp).Row
If ws < 2 Then MsgBox "课程清单为空!": End
cr = .Range("a1:b" & ws)
End With
With Sheets("教师课程总表")
.UsedRange.Clear
.[a3].Resize(2, UBound(ar, 2)) = ar
.[a5].Resize(UBound(br), 1) = br
arr = .Range(.Cells(3, 1), .Cells(rs + 4, y))
For i = 3 To UBound(arr)
If Trim(arr(i, 1)) <> "" Then
d(Trim(arr(i, 1))) = i
End If
Next i
For j = 3 To UBound(arr, 2)
If Trim(arr(1, j)) = "" Then arr(1, j) = arr(1, j - 1)
If Trim(arr(1, j)) <> "" And Trim(arr(2, j)) <> "" Then
zd = Trim(arr(1, j)) & "|" & Trim(arr(2, j))
d(zd) = j
End If
Next j
For i = 2 To UBound(cr)
If Trim(cr(i, 1)) <> "" Then
rr = Split(cr(i, 1), "|")
xh = d(Trim(rr(0)))
zf = Trim(rr(1)) & "|" & Trim(rr(2))
lh = d(zf)
If xh <> "" And lh <> "" Then
arr(xh, lh) = cr(i, 2)
End If
End If
Next i
.Range(.Cells(3, 1), .Cells(rs + 4, y)) = arr
For j = 2 To y Step 13
.Cells(3, j).Resize(1, 13).Merge
Next j
End With
Set d = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|