run time error 91

rjplante

Well-known Member
Joined
Oct 31, 2008
Messages
569
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
For the error:
Code:
'Dim IFilterCell, AFilterCell As Range
Dim IFilterCell, AFilterCell

Split() returns a string array but variant is ok too. Range is not ok.
 
Upvote 0
I changed the line to read "Dim IFilterCell, AFilterCell As String" and now I have a file type mismatch Run time error 13.

 
Upvote 0
Either use what @Kenneth Hobson showed or use
Code:
Dim IFilterCell As Variant, AFilterCell As Variant
They're effectively the same
 
Upvote 0

Forum statistics

Threads
1,216,085
Messages
6,128,733
Members
449,465
Latest member
TAKLAM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top