|
楼主 |
发表于 2014-5-16 20:55
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
1。左图转换成右图
2 分数低于41的删除
3.名字一样的,只保留分数高的那个。。
4.做完后再做个拆分工作簿。
---------------------------------------
做完后我想再做一下第四步。。。- Sub test()
- Dim d As Object
- Dim r%, i%
- Dim arr, brr()
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("人员信息")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:d" & r)
- For i = 1 To UBound(arr)
- If arr(i, 4) > 41 Then
- If Not d.Exists(arr(i, 2)) Then
- d(arr(i, 2)) = i
- Else
- If arr(i, 4) > arr(d(arr(i, 2)), 4) Then
- d(arr(i, 2)) = i
- End If
- End If
- End If
- Next
- End With
- ReDim brr(1 To d.Count, 1 To 4)
- m = 0
- For Each ii In d.Items
- m = m + 1
- For j = 1 To 4
- brr(m, j) = arr(ii, j)
- Next
- Next
- With Worksheets("Sheet2")
- .Range("a1:d1") = Array("学校名称", "姓名", "性别", "分数")
- .Range("a2").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- Sheet2.Activate
- 拆分工作簿
- Sheet1.Activate
- End Sub
- Sub 拆分工作簿()
- Dim arr, brr, d As Object, k, t, a, i&, j&, m&, l&, sh As Worksheet
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- arr = [a2].CurrentRegion
- For i = 2 To UBound(arr)
- d(arr(i, 1)) = d(arr(i, 1)) & "," & i
- Next
- k = d.Keys
- t = d.Items
- brr = arr
- Set sh = ActiveSheet
- For i = 0 To d.Count - 1
- m = 1
- a = Split(t(i), ",")
- For j = 1 To UBound(a)
- m = m + 1
- For l = 1 To UBound(arr, 2)
- brr(m, l) = arr(a(j), l)
- Next
- Next
- sh.Copy
- With ActiveWorkbook
- .Sheets(1).UsedRange.Offset(m).Clear
- .Sheets(1).[a1].Resize(m, UBound(arr, 2)) = brr
- .SaveAs ThisWorkbook.Path & "" & k(i) & ".xls"
- .Close
- End With
- Next
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|