|
楼主 |
发表于 2019-6-8 14:57
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
这个是我在论坛中找到的代码
Option Explicit
Sub 筛选()
Dim d As Object, lr&, ar, r&, k, sh As Worksheet, tt As Range, shtnm$
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each sh In Sheets
If sh.Name <> "物料清单" Then sh.Delete
Next
Application.DisplayAlerts = True
Set d = CreateObject("scripting.dictionary")
With Sheets("物料清单")
lr = .[b65536].End(2).Row
ar = [a1].Resize(lr, 10)
For r = 2 To UBound(ar)
If Len(ar(r, 9)) Then
shtnm = ar(r, 9)
If Not d.exists(shtnm) Then
Set d(shtnm) = .Cells(r, 1).Resize(1, 10)
Else
Set d(shtnm) = Union(d(shtnm), .Cells(r, 1).Resize(1, 10))
End If
End If
Next
End With
If d.Count Then
Set tt = Sheets("物料清单").[a20].Resize(1, 10)
For Each k In d.keys
Sheets.Add After:=Sheets(Sheets.Count)
With ActiveSheet
.Name = k
tt.Copy .[a1]
d(k).Copy .[a2]
.Columns("a:v").AutoFit
.DrawingObjects.Delete
End With
Next
End If
Set d = Nothing
Set tt = Nothing
Sheets("物料清单").Activate
Application.ScreenUpdating = True
MsgBox "分类完成"
End Sub
|
|