Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Code to allow user to enter criteria for autofilter

I would like to write a procedure that would allow a user
to enter dates ie one greater than and the other less than
in a programmed autofilter procedure.

Essentially I would want the user to be able to insert
their own chosen dates in place of the dates that appear
in the undernoted code without them seeing the code.

Selection.AutoFilter Field:=3, Criteria1:="31/10/2002",
Operator:=xlAnd, Criteria2:="<=31/10/2003"

TIA
Ron
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default Code to allow user to enter criteria for autofilter

Ron, how about something like this

Sub test()
Dim strA As String
Dim strB As String
strA = Application.InputBox("Start Date")
strB = Application.InputBox("End Date")

Selection.AutoFilter Field:=3, Criteria1:="" & strA, _
Operator:=xlAnd, Criteria2:="<=" & strB
End Sub


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2000 & 97
** remove news from my email address to reply by email **
"Ron McCormick" wrote in message
...
I would like to write a procedure that would allow a user
to enter dates ie one greater than and the other less than
in a programmed autofilter procedure.

Essentially I would want the user to be able to insert
their own chosen dates in place of the dates that appear
in the undernoted code without them seeing the code.

Selection.AutoFilter Field:=3, Criteria1:="31/10/2002",
Operator:=xlAnd, Criteria2:="<=31/10/2003"

TIA
Ron



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Code to allow user to enter criteria for autofilter

Another option is to create dropdown lists of the dates on the worksheet
using data validation:

http://www.contextures.com/xlDataVal01.html

Create a dropdown for start date, and one for end date, then format
these dates the same as the dates in column C.

The user selects a start and end date from the dropdown lists, then
runs the AutoFilter macro:

'==================================
Selection.AutoFilter Field:=3, Criteria1:="=" & Range("K1").Value, _
Operator:=xlAnd, Criteria2:="<=" & Range("L1").Value
'==================================


Ron McCormick wrote:
I would like to write a procedure that would allow a user
to enter dates ie one greater than and the other less than
in a programmed autofilter procedure.

Essentially I would want the user to be able to insert
their own chosen dates in place of the dates that appear
in the undernoted code without them seeing the code.

Selection.AutoFilter Field:=3, Criteria1:="31/10/2002",
Operator:=xlAnd, Criteria2:="<=31/10/2003"

TIA
Ron



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Code to allow user to enter criteria for autofilter

Thanks Debra & Paul,

Both responses have been helpful, but I have one further
problem. Whenever I run the macro the whole of the list
is hidden. If I then go to Data/Autofilter/Custom and
click OK the filtered list appears. Why does it not
appear automatically?

Thanks again
Ron


-----Original Message-----
Another option is to create dropdown lists of the dates

on the worksheet
using data validation:

http://www.contextures.com/xlDataVal01.html

Create a dropdown for start date, and one for end date,

then format
these dates the same as the dates in column C.

The user selects a start and end date from the dropdown

lists, then
runs the AutoFilter macro:

'==================================
Selection.AutoFilter Field:=3, Criteria1:="=" & Range

("K1").Value, _
Operator:=xlAnd, Criteria2:="<=" & Range("L1").Value
'==================================


Ron McCormick wrote:
I would like to write a procedure that would allow a

user
to enter dates ie one greater than and the other less

than
in a programmed autofilter procedure.

Essentially I would want the user to be able to insert
their own chosen dates in place of the dates that

appear
in the undernoted code without them seeing the code.

Selection.AutoFilter Field:=3,

Criteria1:="31/10/2002",
Operator:=xlAnd, Criteria2:="<=31/10/2003"

TIA
Ron



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Code to allow user to enter criteria for autofilter

The problem may be your regional settings. Try formatting the date as a
number:

'==================================
Selection.AutoFilter Field:=3, Criteria1:="=" &
Str(CDbl(Range("K1").Value)), _
Operator:=xlAnd, Criteria2:="<=" & Str(CDbl(Range("L1").Value))
'==================================

Ron McCormick wrote:
Thanks Debra & Paul,

Both responses have been helpful, but I have one further
problem. Whenever I run the macro the whole of the list
is hidden. If I then go to Data/Autofilter/Custom and
click OK the filtered list appears. Why does it not
appear automatically?

-----Original Message-----
Another option is to create dropdown lists of the dates


on the worksheet

using data validation:

http://www.contextures.com/xlDataVal01.html

Create a dropdown for start date, and one for end date,


then format

these dates the same as the dates in column C.

The user selects a start and end date from the dropdown


lists, then

runs the AutoFilter macro:

'==================================
Selection.AutoFilter Field:=3, Criteria1:="=" & Range


("K1").Value, _

Operator:=xlAnd, Criteria2:="<=" & Range("L1").Value
'==================================


Ron McCormick wrote:

I would like to write a procedure that would allow a


user

to enter dates ie one greater than and the other less


than

in a programmed autofilter procedure.

Essentially I would want the user to be able to insert
their own chosen dates in place of the dates that


appear

in the undernoted code without them seeing the code.

Selection.AutoFilter Field:=3,


Criteria1:="31/10/2002",

Operator:=xlAnd, Criteria2:="<=31/10/2003"


--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

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
Excel vba autofilter code Isis[_2_] Excel Discussion (Misc queries) 0 April 26th 10 05:34 PM
Excel VBA AutoFilter code Isis[_2_] Excel Discussion (Misc queries) 0 April 26th 10 05:31 PM
vba code on autofilter ub Excel Discussion (Misc queries) 1 August 6th 08 08:09 PM
Autofilter code Dominic LeVasseur Excel Discussion (Misc queries) 2 August 16th 06 09:33 PM
Using autofilter, how do I enter several random postcodesinto 'co. novice Excel Discussion (Misc queries) 5 December 4th 04 10:42 PM


All times are GMT +1. The time now is 02:20 AM.

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

About Us

"It's about Microsoft Excel"