Autofilter Criteria Problem

G

Guest

When I try to insert a criteria in an Autofilter using a macro, NO results
are shown. Even when I record the macro, and it works perfectly while
recording, when I run the macro; No results are shown. I used the following
code:

Selection.AutoFilter Field:=5, Criteria1:=">29-4-2003", Operator:=xlAnd, _
Criteria2:="<5-5-2003"

Can anybody see the problem (or even beter; the sollution)? Thanks in advance!
 
M

Mauro Gamberini

Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=">2001/01/03", Operator:=xlAnd
_
, Criteria2:="<2001/01/06"

yyyy/mm/dd
 
G

Guest

I don't know why or how; but it worked! Thanks!
I immidiatly tried to take it a step further, but got stuck again.
Replacing the dates (4-29-2003 en 5-5-2003) by " & k & "and " & h & " I
tried to make this a variable entrance.

It doesn't work though. Giving me an "Overflow Bug" on "h =
Range("A1").Value" the minute I try. Can you seen whats wrong? Thanks in
advance!

Sub FullFunctional()
Dim h As Integer
Dim k As Integer
Sheets("Sheet2").Select
Range("A1:A2").Select
Selection.NumberFormat = "yyyy\m\d"
h = Range("A1").Value
k = Range("A2").Value

Sheets("Sheet2").Select
Columns("E:E").Select
Selection.NumberFormat = "yyyy\m\d"
Cells.Select
Selection.AutoFilter
Selection.AutoFilter Field:=5, Criteria1:=">" & h & "", Operator:=xlAnd, _
Criteria2:="<" & k & ""
 
G

Guest

Have a look at your Dim as Integer for h and k
This will only allow values up to 32767
which in Excel is 16 Sept 1989
If you Dim as Double you should be ok

HTH
RES
 

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

Top