I have pieced together 2 pieces of code. One section runs a sort whilst the other un hides columns and applies a filter.
What I would like to do is clean up the code but am unsure how to do it. In one instance it refers to the Active Workbook.Worksheets and in another instance it refers to the sheet with its code name. I would like to achieve some consistency and prefer to refer to the sheet with its code name - but ActiveWorkbook does not seem to permit this.
Here it is:
What I would like to do is clean up the code but am unsure how to do it. In one instance it refers to the Active Workbook.Worksheets and in another instance it refers to the sheet with its code name. I would like to achieve some consistency and prefer to refer to the sheet with its code name - but ActiveWorkbook does not seem to permit this.
Here it is:
Code:
Private Sub Workbook_Open()
' unhide columns, unfreeze, delete filters and then freeze top row and apply filters
With Sheet3
Activate
If .AutoFilterMode Then .AutoFilterMode = False
.Range("A1:AC1").AutoFilter 'turn filters on
.Columns.Hidden = False 'unhide any columns
Sheet3.Select
.[F2].Select
ActiveWindow.FreezePanes = False 'unfreeze panes
ActiveWindow.FreezePanes = True
End With
ActiveWorkbook.Worksheets("Arr-Dep").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Arr-Dep").Sort.SortFields.Add Key:=Range("L2:L5000"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Arr-Dep").Sort.SortFields.Add Key:=Range( _
"Y2:Y5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Arr-Dep").Sort
.SetRange Range("A1:AA5000")
.Header = xlYes
.Orientation = xlTopToBottom
.Apply
End With
End Sub