|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("达标情况")
- c = .Cells(2, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a2").Resize(2, c)
- ls = UBound(arr, 2)
- For j = 2 To UBound(arr, 2)
- If Len(arr(2, j)) <> 0 Then
- km = Left(arr(1, j), 1)
- If Not d1.exists(km) Then
- m = 1
- ReDim brr(1 To 2, 1 To m)
- Else
- brr = d1(km)
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 2, 1 To m)
- End If
- brr(1, m) = arr(2, j)
- brr(2, m) = j
- d1(km) = brr
- End If
- Next
- End With
- With Worksheets("文科")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(2, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a2").Resize(r - 1, c)
- For j = 5 To UBound(arr, 2)
- If arr(1, j) <> "年排" And arr(1, j) <> "班排" Then
- km = Left(arr(1, j), 1)
- If d1.exists(km) Then
- brr = d1(km)
- For i = 2 To UBound(arr)
- If Not d.exists(arr(i, 2)) Then
- ReDim crr(1 To ls)
- crr(1) = arr(i, 2)
- Else
- crr = d(arr(i, 2))
- End If
- For k = 1 To UBound(brr, 2)
- If arr(i, j) >= brr(1, k) Then
- crr(brr(2, k)) = crr(brr(2, k)) + 1
- End If
- Next
- d(arr(i, 2)) = crr
- Next
- End If
- End If
- Next
- End With
- ReDim drr(1 To d.Count, 1 To ls)
- m = 0
- For Each aa In d.keys
- crr = d(aa)
- m = m + 1
- For j = 1 To UBound(crr)
- drr(m, j) = crr(j)
- Next
- Next
- With Worksheets("达标情况")
- .UsedRange.Offset(3, 0).Clear
- With .Range("a4").Resize(UBound(drr), UBound(drr, 2))
- .Value = drr
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 10
- .Bold = False
- End With
- .Sort key1:=.Range("a4"), order1:=xlAscending, Header:=xlNo
- End With
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
-
- End Sub
复制代码 |
|