Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Why does it keep saying this?

0

I just watched a video on "Searchable Lists in Excel - Easy Method", copied the exact code the guy used, but however, while it runs perfectly for him, mine is not working. It says "Named Argument Not Found" whenever I try to run the search and highlights my first line of code, but I can not figure out what's wrong. (Also, on the file, I have not set up the Input or Field 2)

Sub SearchFi1ters()

Dim MainSheet As Worksheet
Dim MyTable As ListObject

Set MainSheet = Sheets("All WPS 3 or Less Processes")
Set MyTable = MainSheet.ListObjects("WPS_Table")

UserInput = MainSheet.Range("D3").Value
FieldName = MainSheet.Range("D5").Value

If UserInput <> "" Then

    MyTable.AutoFilter.ShowAllData

    If FieldName = "PQR" Then

        MyTable.Range.AutoFilter Field:=2, Criteria:=UserInput

    ElseIf FieldName = "Supported WPS" Then

        MyTable.Range.AutoFilter Field:=3, Criteria:=UserInput

    ElseIf FieldName = "Material 1" Then

        MyTable.Range.AutoFilter Field:=7, Criteria:=UserInput

    ElseIf FieldName = "Material 2" Then

        MyTable.Range.AutoFilter Field:=12, Criteria:=UserInput

    ElseIf FieldName = "Weld Wire 1" Then

        MyTable.Range.AutoFilter Field:=22, Criteria:=UserInput

    ElseIf FieldName = "Weld Wire 2" Then

        MyTable.Range.AutoFilter Field:=31, Criteria:=UserInput

    End If

End If

End Sub
Answer
Discuss

Discussion

Hi Joe and welcome to the Forum. 

Please edit your question to attach a representative Excel file (with no personal data) using the Add Files button. We can then check and reply hopefully. 
John_Ru (rep: 6102) Jun 22, '22 at 4:21 pm
I added the file! Thanks, any help is appreciated
JoeMama (rep: 2) Jun 22, '22 at 4:57 pm
Add to Discussion

Answers

0
Selected Answer

Joe

In the attached revised file, I corrected all the conditional lines like:

If FieldName = "PQR" Then

        MyTable.Range.AutoFilter Field:=2, Criteria:=UserInput

to read:

If FieldName = "PQR" Then

        MyTable.Range.AutoFilter Field:=2, Criteria1:=UserInput

(since "Criteria" without the 1 is not an argument for the AutoFilter method). This now matches the base code in the tutorial from Don  (who owns and runs TeachExcel).

Click ShowAll then enter a valid seach and it should work.

I also reassigned the macros to the buttons (for some reason they didn't work for me).

Hope this fixes your problem.

Discuss

Discussion

p.s. hope you like my Answer and mark it as Selected.

It would help others if you could also edit question title to read something more instructive, like
"Searchable Lists in Excel" keeps saying "Named Argument Not Found" 
John_Ru (rep: 6102) Jun 22, '22 at 5:13 pm
Thank you man!
JoeMama (rep: 2) Jun 22, '22 at 5:22 pm
NP. Thanks for selecting my answer Joe. 
John_Ru (rep: 6102) Jun 22, '22 at 5:24 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login