|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 筛选()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Dim br()
Set d = CreateObject("scripting.dictionary")
With Sheets("数据整合2")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "数据整合2为空!": End
ar = .Range("a1:l" & r)
End With
ReDim br(1 To UBound(ar), 1 To 3)
For i = 2 To UBound(ar)
If Trim(ar(i, 12)) = "" Then
zd = Trim(ar(i, 2)) & "|" & ar(i, 7)
t = d(zd)
If t = "" Then
k = k + 1
d(zd) = k
t = k
br(k, 1) = ar(i, 2)
br(k, 2) = ar(i, 7)
hj = hj + ar(i, 7)
End If
br(t, 3) = br(t, 3) + 1
End If
Next i
If k = "" Then MsgBox "没有需要筛选的数据!": End
With Sheets("TRC留5K")
.[a1].CurrentRegion.Offset(1) = Empty
.[a2].Resize(k, 3) = br
.Columns(5) = Empty
.[a1].Resize(k + 1, 3).Sort .[a1], 1, , , , , , 1 '
If hj <= 5000 Then
.[e2].Resize(k, 1) = .[a2].Resize(k, 1).Value
Else
sl = hj - 5000
For i = 1 To k
hj = hj + br(i, 2)
If hj > 5000 Then
xh = i - 1
Exit For
End If
Next i
If xh <> "" Then
.[e2].Resize(xh, 1) = .[a2].Resize(xh, 1).Value
End If
End If
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|