|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- ls = 14
- With Worksheets("数据源")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a2").Resize(r - 1, c)
- End With
- For i = 1 To UBound(arr)
- xm = arr(i, 25) & "+" & arr(i, 1) & "+" & arr(i, 2)
- If Not d.exists(xm) Then
- ReDim brr(1 To ls)
- brr(1) = arr(i, 25)
- brr(2) = arr(i, 1)
- brr(3) = arr(i, 2)
- Else
- brr = d(xm)
- End If
- brr(4) = brr(4) + 1
- For j = 5 To 14
- If IsNumeric(arr(i, j)) Then
- brr(j) = brr(j) + arr(i, j)
- End If
- Next
- d(xm) = brr
- Next
- ReDim crr(1 To d.Count, 1 To ls)
- m = 0
- For Each aa In d.keys
- brr = d(aa)
- If Len(brr(4)) <> 0 And brr(4) <> 0 Then
- For j = 5 To UBound(brr)
- brr(j) = Application.Round(brr(j) / brr(4), 2)
- Next
- End If
- m = m + 1
- For j = 1 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- Next
- With Worksheets("结果")
- .UsedRange.Offset(2, 0).Clear
- .Range("a3").Resize(UBound(crr), UBound(crr, 2)) = crr
- .Range("a3").Resize(UBound(crr), UBound(crr, 2)).Sort key1:=.Cells(3, 1), order1:=xlAscending, key2:=.Cells(3, 2), order2:=xlAscending, key3:=.Cells(3, 3), order3:=xlAscending, Header:=xlNo
- With .Range("a2").Resize(1 + UBound(crr), UBound(crr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 10
- End With
- End With
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- .Rows(2).Resize(1 + UBound(crr)).RowHeight = 18
- End With
- End Sub
复制代码 |
|