|
楼主 |
发表于 2023-5-2 15:48
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
您的代码是不是好像没有考虑到:3、按顺序,有条件选取A列复制到E2:E(条件:当B列和值达到小于等于B列总和-5000即可,不足5000全选)
Sub 筛选出()
Dim d As Object, a, b
Dim ss$, n%, i%
Sheet2.UsedRange.Offset(1, 0) = ""
m = Sheet1.Cells(Rows.Count, 2).End(xlUp).Row
a = Sheet1.Range("a1:l" & m)
Set d = CreateObject("scripting.dictionary")
ReDim b(1 To UBound(a), 1 To 5)
For i = 2 To UBound(a)
If a(i, 12) = "" Then
ss = a(i, 2)
If Not d.Exists(ss) Then
n = n + 1
d.Add ss, n
b(n, 1) = a(i, 2): b(n, 2) = a(i, 7): b(n, 3) = 1: b(n, 5) = b(n, 1)
Else
b(d(ss), 3) = b(d(ss), 3) + 1
End If
End If
Next
[a2].Resize(n, 5) = b
Range("a1:e" & n + 1).Sort Key1:=Range("C2"), Order1:=xlAscending, Header:=1
End Sub |
|