PhosFeedLogisticsMan
New Member
- Joined
- Aug 9, 2017
- Messages
- 17
I currently have a sub in my workbook, that sorts some data, then creates tabs based on a range and the Array argument. The problem I see is when I leave or for someone without experience in VBA would need to add or delete some of the Array arguments. I want to get rid of the code, and maintain this list in a worksheet within the workbook(calling it SCAC_Codes). Then any user can maintain that worksheet adding and deleting the data in Column A. Here is what I currently have with some formatting towards the end. Can anyone help? I'm not a guru with this VBA stuff, but am learning. Here is my code:
Sub NewOrders_FilterToSheets()
'
'
'
Application.ScreenUpdating = False
Sheets("NewOrders").Activate
ActiveWorkbook.Worksheets("NewOrders").AutoFilter.Sort.SortFields.Clear
On Error Resume Next
ActiveSheet.ShowAllData
Dim SourceSheet As Worksheet
Dim TargetSheet As Worksheet
Dim SheetNames As Variant
Dim i As Long
Dim LR As Long
'EDIT
Set SourceSheet = Sheets("NewOrders")
SheetNames = Array("BLHW", "CCTI", "CCTI", "RLRN", "CMMO", "WLPO", "SWGQ", "RJSV", "OKLB", "ADMH", "BNTI", "BTXR", "DDGR", "DONM", "ECBI", "KCAR", "MEYT", "NOWN", "PAIS", "TATQ", "TUTU", "TYDS", "VHTI", "MYER", "SKYV", "LKNW", "HINT", "VANT")
Const FilterColumn = 1
'END EDIT
With SourceSheet
LR = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 0 To UBound(SheetNames)
Set TargetSheet = Worksheets(SheetNames(i))
TargetSheet.Cells.ClearContents
With .Range("A2:Q" & LR)
.AutoFilter Field:=FilterColumn, Criteria1:=SheetNames(i)
.Offset(0, 0).Copy TargetSheet.Range("A1")
End With
Next i
End With
Sheets(Array("BLHW", "CCTI", "CCTI", "RLRN", "CMMO", "WLPO", "SWGQ", "RJSV", "OKLB", "ADMH", "BNTI", "BTXR", "DDGR", "DONM", "ECBI", "KCAR", "MEYT", "NOWN", "PAIS", "TATQ", "TUTU", "TYDS", "VHTI", "MYER", "SKYV", "LKNW", "HINT", "VANT")).Select
Range("A:Q").Columns.AutoFit
Cells.Select
Cells.EntireColumn.AutoFit
Columns("O:Q").Select
Selection.ColumnWidth = 35.01
Columns("B").Select
Selection.ColumnWidth = 10.01
Columns("C").Select
Selection.ColumnWidth = 25.01
Columns("D").Select
Selection.ColumnWidth = 6.01
Columns("E").Select
Selection.ColumnWidth = 25.01
Columns("F:G").Select
Selection.ColumnWidth = 25.01
Columns("H").Select
Selection.ColumnWidth = 6.01
Columns("I").Select
Selection.ColumnWidth = 25.01
Columns("J").Select
Selection.ColumnWidth = 25.01
Columns("K").Select
Selection.ColumnWidth = 5.01
Columns("L").Select
Selection.ColumnWidth = 5.01
Columns("M").Select
Selection.ColumnWidth = 5.01
Columns("N").Select
Selection.ColumnWidth = 25.01
Columns("O").Select
Selection.ColumnWidth = 25.01
'Columns("P").Select
'Selection.ColumnWidth = 35.01
'Columns("Q").Select
'Selection.ColumnWidth = 25.01
Cells.Select
Cells.EntireRow.AutoFit
Sheets("MENU").Activate
'Calling other subs
RemoveEmptySheets
ChangeSubjectNewLoads
ChangeBodyNewLoads
HideNewOrders
CCtoOORorNot
Application.ScreenUpdating = True
End Sub
Sub NewOrders_FilterToSheets()
'
'
'
Application.ScreenUpdating = False
Sheets("NewOrders").Activate
ActiveWorkbook.Worksheets("NewOrders").AutoFilter.Sort.SortFields.Clear
On Error Resume Next
ActiveSheet.ShowAllData
Dim SourceSheet As Worksheet
Dim TargetSheet As Worksheet
Dim SheetNames As Variant
Dim i As Long
Dim LR As Long
'EDIT
Set SourceSheet = Sheets("NewOrders")
SheetNames = Array("BLHW", "CCTI", "CCTI", "RLRN", "CMMO", "WLPO", "SWGQ", "RJSV", "OKLB", "ADMH", "BNTI", "BTXR", "DDGR", "DONM", "ECBI", "KCAR", "MEYT", "NOWN", "PAIS", "TATQ", "TUTU", "TYDS", "VHTI", "MYER", "SKYV", "LKNW", "HINT", "VANT")
Const FilterColumn = 1
'END EDIT
With SourceSheet
LR = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 0 To UBound(SheetNames)
Set TargetSheet = Worksheets(SheetNames(i))
TargetSheet.Cells.ClearContents
With .Range("A2:Q" & LR)
.AutoFilter Field:=FilterColumn, Criteria1:=SheetNames(i)
.Offset(0, 0).Copy TargetSheet.Range("A1")
End With
Next i
End With
Sheets(Array("BLHW", "CCTI", "CCTI", "RLRN", "CMMO", "WLPO", "SWGQ", "RJSV", "OKLB", "ADMH", "BNTI", "BTXR", "DDGR", "DONM", "ECBI", "KCAR", "MEYT", "NOWN", "PAIS", "TATQ", "TUTU", "TYDS", "VHTI", "MYER", "SKYV", "LKNW", "HINT", "VANT")).Select
Range("A:Q").Columns.AutoFit
Cells.Select
Cells.EntireColumn.AutoFit
Columns("O:Q").Select
Selection.ColumnWidth = 35.01
Columns("B").Select
Selection.ColumnWidth = 10.01
Columns("C").Select
Selection.ColumnWidth = 25.01
Columns("D").Select
Selection.ColumnWidth = 6.01
Columns("E").Select
Selection.ColumnWidth = 25.01
Columns("F:G").Select
Selection.ColumnWidth = 25.01
Columns("H").Select
Selection.ColumnWidth = 6.01
Columns("I").Select
Selection.ColumnWidth = 25.01
Columns("J").Select
Selection.ColumnWidth = 25.01
Columns("K").Select
Selection.ColumnWidth = 5.01
Columns("L").Select
Selection.ColumnWidth = 5.01
Columns("M").Select
Selection.ColumnWidth = 5.01
Columns("N").Select
Selection.ColumnWidth = 25.01
Columns("O").Select
Selection.ColumnWidth = 25.01
'Columns("P").Select
'Selection.ColumnWidth = 35.01
'Columns("Q").Select
'Selection.ColumnWidth = 25.01
Cells.Select
Cells.EntireRow.AutoFit
Sheets("MENU").Activate
'Calling other subs
RemoveEmptySheets
ChangeSubjectNewLoads
ChangeBodyNewLoads
HideNewOrders
CCtoOORorNot
Application.ScreenUpdating = True
End Sub