run time error 91

rjplante

Well-known Member
Joined
Oct 31, 2008
Messages
574
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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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