|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 抽取数据()
Application.ScreenUpdating = False
Dim ar As Variant
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With ActiveSheet
r = .Cells(Rows.Count, 4).End(xlUp).Row
If r < 5 Then MsgBox "数据源为空!": End
ar = .Range("d4:g" & r)
End With
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) <> "" Then
d(Trim(ar(i, 3))) = ar(i, 1)
End If
Next i
For Each k In d.keys
n = 0
ReDim cr(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) = k Then
n = n + 1
For j = 1 To UBound(ar, 2)
cr(n, j) = ar(i, j)
Next j
End If
Next i
For i = 1 To n
For s = i + 1 To n
If cr(i, 3) > cr(s, 3) Then
For j = 1 To UBound(cr, 2)
kk = cr(i, j)
cr(i, j) = cr(s, j)
cr(s, j) = kk
Next j
End If
Next s
Next i
sl = d(k)
For i = 1 To sl
m = m + 1
For j = 1 To UBound(cr, 2)
br(m, j) = cr(i, j)
Next j
Next i
Next k
With Sheets("抽检结果")
.[a1].CurrentRegion.Offset(1) = Empty
.[a2].Resize(m, UBound(br, 2)) = br
.Select
End With
Set d = Nothing
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|