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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
Where are the quotes (") around the criteria?:eek:
 
Upvote 0

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Try like this

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

Hope this helps...
 
Upvote 0

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
David

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

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

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
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

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
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

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
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,191,202
Messages
5,985,244
Members
439,953
Latest member
suchitha

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
Top