I need to cycle through the first 3 sheets of an Excel workbook and execute some code when it gets opened.
This is my code:
Private Sub Workbook_Open()
Dim I As Integer
For I = 1 To 3
Sheets(I).Select
sam_crm = Range("I2").Value
ActiveSheet.ListObjects(1).Range.AutoFilter Field:=1, Criteria1:=sam_crm
ActiveSheet.ListObjects(2).Range.AutoFilter Field:=5, Criteria1:=sam_crm
ActiveSheet.ListObjects(2).Range.AutoFilter Field:=1, Criteria1:="<>*" & sam_crm & "*", Operator:=xlAnd
Next I
Sheets(1).Select
End Sub
I get
error 1004, select method of the worksheet object could not be executed
I'm using the German version of excel, so I don't know the exact English error message. It is working fine with Excel 2007, but since the last update it isn't working on the newer versions.