Desu Nota from Columbus
Well-known Member
- Joined
- Mar 17, 2011
- Messages
- 556
I am wondering if it is possible to condense the following code using a FOR statement:
Earlier in the macro I created and named sheets to exactly match Criteria1 (ex. Line1, Line6, Line10, etc.).
Is it possible to code the following statement?
For Criteria1 = "Line1", "Line2",..., "Line6", "Line10"
Select All Visible Cells and paste to Sheet Name = Criteria1
Code:
Sheets("All Assets").Select
Cells.Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="Line1"
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Line1").Paste
Sheets("All Assets").Select
Selection.AutoFilter Field:=1, Criteria1:="Line2"
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Line2").Paste
Sheets("All Assets").Select
Selection.AutoFilter Field:=1, Criteria1:="Line3"
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Line3").Paste
Sheets("All Assets").Select
Selection.AutoFilter Field:=1, Criteria1:="Line4"
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Line4").Paste
Sheets("All Assets").Select
Selection.AutoFilter Field:=1, Criteria1:="Line5"
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Line5").Paste
Sheets("All Assets").Select
Selection.AutoFilter Field:=1, Criteria1:="Line6"
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Line6").Paste
Sheets("All Assets").Select
Selection.AutoFilter Field:=1, Criteria1:="Line10"
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Line10").Paste
Sheets("All Assets").Select
Selection.AutoFilter Field:=1, Criteria1:="Flowline"
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Flowline").Paste
Sheets("All Assets").Select
Selection.AutoFilter Field:=1, Criteria1:="Lamination"
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Lamination").Paste
Sheets("All Assets").Select
Selection.AutoFilter Field:=1, Criteria1:="Grinding"
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Grinding").Paste
Is it possible to code the following statement?
For Criteria1 = "Line1", "Line2",..., "Line6", "Line10"
Select All Visible Cells and paste to Sheet Name = Criteria1