|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 分类()
Dim i As Long
Dim j As Long
Dim k As Long
Dim vData As Variant
Dim d As Object
Set d = CreateObject("Scripting.Dictionary")
Dim ws As Worksheet
Dim vKey As Variant
Dim vRlt As Variant
Dim vRow As Variant
vData = Sheet2.Range("A1:D" & Sheet2.Cells(Rows.Count, 4).End(xlUp).Row)
For i = 5 To UBound(vData)
If Not d.exists(vData(i, 4)) Then
d(vData(i, 4)) = i
Else
d(vData(i, 4)) = d(vData(i, 4)) & "," & i
End If
Next
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Each ws In Worksheets
ws.Visible = xlSheetVisible
If ws.Name <> Sheet1.Name And ws.Name <> Sheet2.Name And ws.Name <> Sheet3.Name And ws.Name <> Sheet4.Name Then ws.Delete
Next
For Each vKey In d.keys
vRow = Split(d(vKey), ",")
ReDim vRlt(1 To UBound(vRow) + 1, 1 To 3)
For j = 1 To UBound(vRlt)
vRlt(j, 1) = vData(vRow(j - 1), 4)
vRlt(j, 2) = vData(vRow(j - 1), 2)
vRlt(j, 3) = vData(vRow(j - 1), 3)
Next
Sheet1.Copy after:=Worksheets(Worksheets.Count)
With Worksheets(Worksheets.Count)
.Name = vKey
.Range("C3").Resize(UBound(vRlt), 3) = vRlt
End With
Next
Sheet3.Visible = xlSheetHidden
Sheet4.Visible = xlSheetHidden
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Set ws = Nothing
Set d = Nothing
End Sub
|
|