Search Using Autofilter - Field

  • Thread starter Thread starter Ben Allen
  • Start date Start date
B

Ben Allen

I have numerous options a user can pick and depending on this the field of
an autofilter must change, my code does not appear to work. Any Ideas?
Thanks
Private Sub Search_Click()
Range("B3:L10").Select
'Set Field
Dim myField As Integer
If DateOp = True Then
Set myField = 1
ElseIf TourRef = True Then
Set myField = 2
ElseIf Country = True Then
Set myField = 3
ElseIf Place = True Then
Set myField = 4
ElseIf Spaces = True Then
Set myField = 10
End If
Selection.AutoFilter Field:=myFeild, Criteria1:=Search.Value,
Operator:=xlAnd

End Sub

--
Cheers,
Ben

Remove your.tonsils to reply
"You only live once but if you do it right once is enough!"
 
First, put

Option Explicit

At the top of your module. This'll force you to declare all your variables. It
may sound like more work, but it'll save you time searching for typos:

Set myField = 1
Field:=myFeild

myFeild is misspelled.

And drop those Set's. You use those when you work with objects--ranges,
worksheets, workbooks, not simple integers/longs/strings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Macro 1
Print Macro 1
Error Handling Help 0
Field changes per senario 1
Need help in printing vba code 0
Macro for Autofiltering certain dates 1
Help me4 2
If/Elseif AutoFilter Macro 4

Back
Top