|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim d As New Dictionary
- Dim d1 As New Dictionary
- Dim r%, i%, c%, j%
- Dim arr, brr()
- With Worksheets("1、【全部岗位】岗位等级序列表")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- arr = .Range("d3:f" & r)
- End With
- n = 1
- For i = 1 To UBound(arr)
- If Not d1.Exists(arr(i, 1)) Then
- n = n + 1
- d1(arr(i, 1)) = n
- End If
- If Not d.Exists(arr(i, 2)) Then
- Set d(arr(i, 2)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 2)).Exists(arr(i, 1)) Then
- m = 1
- ReDim brr(1 To m)
- Else
- brr = d(arr(i, 2))(arr(i, 1))
- m = UBound(brr) + 1
- ReDim Preserve brr(1 To m)
- End If
- brr(m) = Mid(arr(i, 3), InStr(arr(i, 3), "】") + 1)
- d(arr(i, 2))(arr(i, 1)) = brr
- Next
- With Worksheets("sheet1")
- .Cells.Clear
- .Range("b1").Resize(1, d1.Count) = d1.Keys
- .Range("a1") = "岗级"
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- For Each aa In d.Keys
- r0 = .UsedRange.Find(what:="*", lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row + 1
- For Each bb In d(aa).Keys
- brr = d(aa)(bb)
- .Cells(r0, d1(bb)).Resize(UBound(brr), 1) = Application.Transpose(brr)
- Next
- r1 = .UsedRange.Find(what:="*", lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row + 1
- With .Cells(r0, 1)
- .Value = aa
- .Resize(r1 - r0).Merge
- End With
- For j = 2 To c
- r2 = .Cells(.Rows.Count, j).End(xlUp).Row
- If r2 <= r0 Then
- .Cells(r0, j).Resize(r1 - r0).Merge
- End If
- Next
- Next
- r = .UsedRange.Find(what:="*", lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
- With .Range("a1").Resize(r, c)
- .Borders.LineStyle = xlContinuous
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
|