Hi all,
I use this code to filter data in my workbook;
I notice that this code is not working under Workbook_Open()
When i paste it in a module and press on an button it works.
I would like to make this code work when i open the workbook. Anyone knows why it's not working under workbook_Open()?
I use this code to filter data in my workbook;
Code:
Private Sub Workbook_Open()On Error GoTo Errorhandler
Workbooks("Persnlk.xls").Close SaveChanges:=False
Workbooks("VB_Macros.xls").Close SaveChanges:=False
Worksheets("Shifts").AutoFilterMode = False
Worksheets("Shifts").Range("J1:Q" & Range("J" & Rows.Count).End(xlUp).Row).ClearContents
Worksheets("Shifts").Range("A1").AutoFilter Field:=2, Criteria1:="<>"
Worksheets("Shifts").Range("A1").AutoFilter Field:=3, Criteria1:="<>"
Worksheets("Shifts").AutoFilter.Range.Copy
Worksheets("Shifts").Range("J1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Worksheets("Shifts").AutoFilterMode = False
Exit Sub
Errorhandler:
End Sub
I notice that this code is not working under Workbook_Open()
When i paste it in a module and press on an button it works.
I would like to make this code work when i open the workbook. Anyone knows why it's not working under workbook_Open()?