rjplante
Well-known Member
- Joined
- Oct 31, 2008
- Messages
- 574
- Office Version
- 365
- Platform
- Windows
I have two worksheets and the internal cell reference is identical for each worksheet. When I run the macro and I am on Sheet A to start with, everything works fine. When I am on Sheet B, the macro crashes on the AFilterCell line and gives me a Runtim91 error. What is causing this to fail. If I change the line to Set AFilterCell = bla bla bla then I get an error 424. Help? What do I need to do to fix this issue?
Code:
Dim IFilterCell, AFilterCell As Range
Application.ScreenUpdating = False
If Range("EE1").Value = "Sheet A" Then
IFilterCell = Split(Sheets("Sheet A").Range("EG2").Value, ",")
Sheets("Sheet A").Select
' Filter for Selected tools (Column T = 20)
ActiveSheet.Range("$A$2:$AL2" & lastrow).AutoFilter Field:=20, Criteria1:=IFilterCell, Operator:=xlFilterValues
ElseIf Range("EE1").Value = "Sheet B" Then
AFilterCell = Split(Sheets("Sheet B").Range("EG2").Value, ",")
Sheets("Sheet A").Select
' Filter for Selected tools (Column E = 5)
ActiveSheet.Range("$A$2:$AF2" & lastrow).AutoFilter Field:=5, Criteria1:=AFilterCell, Operator:=xlFilterValues
End If