Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Search Using Autofilter - Field

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!"


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Search Using Autofilter - Field

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.



Ben Allen wrote:

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!"


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic autofilter field merry_fay Excel Discussion (Misc queries) 2 March 17th 10 02:11 PM
Windows search in Excel with autofilter Dave Z Excel Discussion (Misc queries) 1 January 21st 05 07:44 PM
Search using Autofilter Ben Allen Excel Programming 2 April 16th 04 12:10 PM
using autofilter to search 2 columns neowok[_11_] Excel Programming 6 February 19th 04 02:40 PM
Use sheet name as search string or autofilter criteria Magar Excel Programming 1 November 14th 03 01:06 PM


All times are GMT +1. The time now is 08:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"