Modify Code

davidhall80

Well-known Member
Joined
Jul 8, 2006
Messages
663
I'm trying to automate this search, but VB isn't accepting the last 2 lines of code...Any ideas. Code is pretty self explanatory. Thanks in advance


Sub Asso_Name_Search()
On Error Resume Next
ActiveSheet.ShowAllData
First = InputBox("Enter 1st Name String")
Second = InputBox("Enter 2nd Name String")
Selection.AutoFilter Field:=2, Criteria1:=*First*
Selection.AutoFilter Field:=3, Criteria1:=*Second*
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Where are the quotes (") around the criteria?:eek:
 
Upvote 0
Try like this

Selection.AutoFilter Field:=2, Criteria1:="*" & First & "*"
Selection.AutoFilter Field:=3, Criteria1:="*" & Second & "*"

Hope this helps...
 
Upvote 0
David

Sorry but that doesn't really make sense, to me anyway.:)

Without quotes the code wouldn't even compile.:eek:
 
Upvote 0
Sorry but that doesn't really make sense, to me anyway.:)

Without quotes the code wouldn't even compile.:eek:

The critiera First and Second, those were Variables, not Text Stings..That's why OP didn't have quotes...

OP was trying to filter on CONTAINS - VARIABLE (First Second)...that's what the * were for...
 
Upvote 0
Jonmo

And where in that code where the variables either declared or given a value.:eek:

Do you know something I don't?:)
 
Upvote 0
Sub Asso_Name_Search()
On Error Resume Next
ActiveSheet.ShowAllData
First = InputBox("Enter 1st Name String")
Second = InputBox("Enter 2nd Name String")
Selection.AutoFilter Field:=2, Criteria1:=*First*
Selection.AutoFilter Field:=3, Criteria1:=*Second*
End Sub
:)
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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