Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering issues with macro

Status
Not open for further replies.

tinmar

Technical User
Mar 24, 2003
55
HK
Im trying to run a macro which will pick date A and Date B and give me the data inbetween the 2 dates. Im using the below macro, but doesnt seem to work on the line in which starts the autofilter


Sub DateSelection()
'
'This macro will ask for the date from an input box'
'

Dim mycriteria As String

mycriteria = Range("A1").Value

Dim firstdate As String

firstdate = Range("A11").Value


Sheets("Sheet3").Select
Cells.Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:"=>mycriteria", Operator:=xlAnd" _
, Criteria2:"=<firstdate"

Rows("1:1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("sheet1").Select

End Sub
 
Perhaps this (typed, untested) ?
Selection.AutoFilter Field:=1, Criteria1:=">" & mycriteria, Operator:=xlAnd _
, Criteria2:="<" & firstdate
Or this ?
Selection.AutoFilter Field:=1, Criteria1:=">""" & mycriteria & """", Operator:=xlAnd _
, Criteria2:="<""" & firstdate & """"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top