Autofilter Error Class Out Of Range - 1004

DiscoSte

New Member
Joined
Feb 17, 2021
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi Folks

I am trying to use an Input Box to filter results on a seperate non-active Sheet. (ExportData). I get the error as mentioned in the title and the debug points to line 7. .Autofilter Field:=5.....
My VBA code is mostly 'borrowed' from elsewhere, so I'm not 100% sure what I've got wrong


VBA Code:
Option Explicit
Public Sub Filter()
    Application.ScreenUpdating = False
    Dim strName As String
    strName = InputBox("Please enter required date")
    With Sheets("ExportData").Range("$A$1:$Z$1000")
        .AutoFilter Field:=7, Criteria1:="*" & strName & "*"
        .AutoFilter
    End With
    Application.ScreenUpdating = True
End Sub


Any assistance is greatly appreciated. Thank you.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
A few things:

1. Do not use reserved words like "Filter" for the names of procedures, variables, or functions. That could cause errors and other unexpected results.
2. You do not need the "*" around your criteria. That is when you are looking for a partial text entry max, not a date match.
3. I believe your second ".AutoFilter" line is shutting off the filter you are applying in the line above.

See if thise does what you want:
VBA Code:
Public Sub MyFilter()
    Application.ScreenUpdating = False
    Dim strName As String
    strName = InputBox("Please enter required date")
    With Sheets("ExportData").Range("$A$1:$Z$1000")
        .AutoFilter Field:=7, Criteria1:=strName
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

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