View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Autofilter - Applying changes

Norman,
Just for clarification (I don't have this problem or have a way to test it),
you must include the clng - just the dateserial doesn't work?
( as I recall you are using a Non-US version of Excel)
--
Regards,
Tom Ogilvy

"Norman Jones" wrote in message
...
Hi Nigel,

The following version worked for me:

Sub Tester()

Range("A4:C4").Select
Selection.AutoFilter
Selection.AutoFilter Field:=2, _
Criteria1:="=" & CLng(DateSerial(2005, 10, 19)), _
Operator:=xlAnd, _
Criteria2:="<=" & CLng(DateSerial(2005, 11, 15))
End Sub


---
Regards,
Norman



"Nigel" wrote in message
...
Hi Tom
I have continued to investigate. It is definitely the date format that

is
causing the problem. If I set the dates on the worksheet to US format

and
set the filter conditional to the same it works. So it appears that
running the filter manually Excel will resolve the date based on local
settings. But VBA uses the US form of dates so when that is applied,

the
sheet is has an incompatible format. Similar problem to userform control
of
dates.
My problem remains, as I cannot figure out the conversion process, it
seems
VBA always uses US format dates. Any ideas as a workaround?

--
Cheers
Nigel



"Tom Ogilvy" wrote in message
...
try

Range("A4:C4").Select
Selection.AutoFilter
Selection.AutoFilter Field:=3, Criteria1:="=" &
DateSerial(2005,10,19),

_
Operator:=xlAnd, Criteria2:="=" & DateSerial(2005,11,15)

--
Regards,
Tom Ogilvy

"Nigel" wrote in message
...
Hi All
I am using an autofilter under VBA control. To set up the customer
conditions I record the macro and adapt the code as required.

Manually the filter works ok, and the resulting code is created and

the
filter acts immediately on the datalist showing only those meeting

the
criteria specified. The filter relate to some date ranges shown on

the
sheet
in European format.

If I remove the filter and run the recorded macro, the filter is put

in
place, the Custom conditions are set BUT all rows are filtered. If I

open
the filter to check the criteria settings, they are as requested by

the
macro. If I then click OK on the filter the resultant list is

filtered
correctly with conditions being applied correctly !!

I suspect it is to do with the DATES - but cannot reconcile the

difference
between the Manual application and the VBA macro? Thoughts anyone?

Using Xl97 (v8) as the target application, but I get the same in xlXP
(v10).

Recorded (unedited code below)

Range("A4:C4").Select
Selection.AutoFilter
Selection.AutoFilter Field:=3, Criteria1:="=19/10/2005",
Operator:=xlAnd
_
, Criteria2:="=15/11/2005"


--
Cheers
Nigel