|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("部颁课时")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(2, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a2").Resize(r - 1, c)
- For i = 2 To UBound(arr)
- bj = InStr("一二三四五六七八九", arr(i, 1))
- Set d1(bj) = CreateObject("scripting.dictionary")
- For j = 2 To UBound(arr, 2)
- If Len(arr(i, j)) <> 0 Then
- d1(bj)(arr(1, j)) = arr(i, j)
- End If
- Next
- Next
- 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
- For i = 2 To UBound(arr)
- bj = Val(Left(arr(i, 1), 1))
- If d1.exists(bj) Then
- For j = 2 To UBound(arr, 2)
- If Len(arr(i, j)) <> 0 Then
- If d1(bj).exists(arr(1, j)) Then
- If Not d.exists(arr(i, j)) Then
- ReDim brr(1 To 2)
- brr(1) = arr(i, 1) & arr(1, j) & d1(bj)(arr(1, j))
- Else
- brr = d(arr(i, j))
- brr(1) = brr(1) & ";" & arr(1, j) & d1(bj)(arr(1, j))
- End If
- brr(2) = brr(2) + d1(bj)(arr(1, j))
- d(arr(i, j)) = brr
- End If
- End If
- Next
- End If
- Next
- With Worksheets("课时分担一览表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Range("c2:d" & r).ClearContents
- arr = .Range("a2:d" & r)
- For i = 1 To UBound(arr)
- If d.exists(arr(i, 2)) Then
- brr = d(arr(i, 2))
- arr(i, 3) = brr(1)
- arr(i, 4) = brr(2)
- End If
- Next
- .Range("a2:d" & r) = arr
- End With
- End Sub
复制代码 |
|