|
こんにちは。
別解です。
データシートをアクティブとした状態で、かつデータシートの1行目は項目名として。
Sub bobo()
Dim roe As Long, coe As Integer, DtSh As Worksheet
Set DtSh = ActiveSheet
roe = DtSh.Cells(Rows.Count, "D").End(xlUp).Row
coe = DtSh.Cells(1, Columns.Count).End(xlToLeft).Column
bumo = Array("CJ20", "CJ50", "CJ70")
Application.ScreenUpdating = False
For i = 0 To UBound(bumo)
DtSh.Range("D1:D" & roe).AutoFilter Field:=1, Criteria1:=bumo(i)
Worksheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = bumo(i)
DtSh.Rows(1).Copy Sheets(bumo(i)).Range("A1")
DtSh.Range("A2", DtSh.Cells(roe, coe)).SpecialCells(xlCellTypeVisible).Copy Sheets(bumo(i)).Range("A2")
DtSh.Range("A" & roe).AutoFilter
Next
Application.ScreenUpdating = True
End Sub
|
|