返回列表 上一主題 發帖

[發問] 請問如何依篩選欄的類別,自動建立分頁建立後並分類資料?

Sub test()
Dim Sht As Worksheet, xD, xR As Range
Set xD = CreateObject("Scripting.Dictionary")
xD("") = 1
With Sheets("彙總明細").UsedRange
  For Each xR In .Columns(2).Offset(1, 0).Cells
    If xD(xR.Value) = "" Then
     On Error Resume Next
     Set Sht = Sheets(xR.Value)
     On Error GoTo 0
     If Sht Is Nothing Then Sheets.Add(after:=Sheets(Sheets.Count)).Name = xR.Value
     .AutoFilter Field:=2, Criteria1:=xR.Value
     .Columns("a:d").Copy Sheets(xR.Value).[a1]
     xD(xR.Value) = 1: Set Sht = Nothing
    End If
  Next
  Application.Goto .Item(1)
End With
Sheets("彙總明細").AutoFilterMode = False
End Sub
 

TOP

        靜思自在 : 改變自己是自救,影響別人是救人。
返回列表 上一主題