Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Date flips around when using Autofilter in VB

I'm using VB to autofilter a number of worksheets using a criteria entered in
a textbox.

--------------------------------------------------------------------------------
Sub Filter_Box3()

Dim ws As Worksheet
Dim crit As String
Dim agsheetname As String

crit = Sheet1.Filtertext2.Value

Application.ScreenUpdating = False

For Each ws In Worksheets
agsheetname = ws.Name
If agsheetname < "Guide" Then

ws.UsedRange.AutoFilter Field:=1, Criteria1:="<" & crit

End If

Next ws

Application.ScreenUpdating = True

End Sub

--------------------------------------------------------------------------------

for some reason, when using < or the date has been flipped around when i
check the autofilter settings on the worksheets, so that if crit =
01/02/2005, it gets changed to 02/01/2005. This does not happen when using =
in the criteria. Even when i hard code a date into the function like:

-------------------------------------------------------------------------------
ws.UsedRange.AutoFilter Field:=1, Criteria1:="<01/02/2005"

--------------------------------------------------------------------------------

.... it still gets flipped around.

Any ideas?

El.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date flips around when using Autofilter in VB

ws.UsedRange.AutoFilter Field:=1, Criteria1:="<" & _
format(cdate("01/02/2005"),"mm/dd/yyyyy")

I would bet you have the problem even with "=" if the month and day can be
flipped and still form a good date.

In VBA, you need to work with US formatted dates if you are going to work
with strings, otherwise, work with date serial numbers.

--
Regards,
Tom Ogilvy


"elsandalos" wrote in message
...
I'm using VB to autofilter a number of worksheets using a criteria entered

in
a textbox.

--------------------------------------------------------------------------

------
Sub Filter_Box3()

Dim ws As Worksheet
Dim crit As String
Dim agsheetname As String

crit = Sheet1.Filtertext2.Value

Application.ScreenUpdating = False

For Each ws In Worksheets
agsheetname = ws.Name
If agsheetname < "Guide" Then

ws.UsedRange.AutoFilter Field:=1, Criteria1:="<" & crit

End If

Next ws

Application.ScreenUpdating = True

End Sub

--------------------------------------------------------------------------

------

for some reason, when using < or the date has been flipped around when i
check the autofilter settings on the worksheets, so that if crit =
01/02/2005, it gets changed to 02/01/2005. This does not happen when using

=
in the criteria. Even when i hard code a date into the function like:

--------------------------------------------------------------------------

-----
ws.UsedRange.AutoFilter Field:=1, Criteria1:="<01/02/2005"

--------------------------------------------------------------------------

------

... it still gets flipped around.

Any ideas?

El.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Date flips around when using Autofilter in VB

Cheers Tom.

Oddly i don't get the problem when using "=", even if the month and day can
be flipped. I've just read around, and seen that people are using cdbl when
feeding a date into the autofilter. I've got it fixed with that, and also
using your method.

still strikes me as odd though. Whats the difference between feeding
autofilter a criteria through VB and doing it manually on the worksheet?

Anyway - ta for the help :)

El.



"Tom Ogilvy" wrote:

ws.UsedRange.AutoFilter Field:=1, Criteria1:="<" & _
format(cdate("01/02/2005"),"mm/dd/yyyyy")

I would bet you have the problem even with "=" if the month and day can be
flipped and still form a good date.

In VBA, you need to work with US formatted dates if you are going to work
with strings, otherwise, work with date serial numbers.

--
Regards,
Tom Ogilvy


"elsandalos" wrote in message
...
I'm using VB to autofilter a number of worksheets using a criteria entered

in
a textbox.

--------------------------------------------------------------------------

------
Sub Filter_Box3()

Dim ws As Worksheet
Dim crit As String
Dim agsheetname As String

crit = Sheet1.Filtertext2.Value

Application.ScreenUpdating = False

For Each ws In Worksheets
agsheetname = ws.Name
If agsheetname < "Guide" Then

ws.UsedRange.AutoFilter Field:=1, Criteria1:="<" & crit

End If

Next ws

Application.ScreenUpdating = True

End Sub

--------------------------------------------------------------------------

------

for some reason, when using < or the date has been flipped around when i
check the autofilter settings on the worksheets, so that if crit =
01/02/2005, it gets changed to 02/01/2005. This does not happen when using

=
in the criteria. Even when i hard code a date into the function like:

--------------------------------------------------------------------------

-----
ws.UsedRange.AutoFilter Field:=1, Criteria1:="<01/02/2005"

--------------------------------------------------------------------------

------

... it still gets flipped around.

Any ideas?

El.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date flips around when using Autofilter in VB

cdbl used with a date string such as

cdbl("01/23/2005")

won't work. so you must not be sending it a date string.

anyway, the difference is that one is done with VBA and one is done with
Excel. They are two different products and have different behaviors.

--
Regards,
Tom Ogilvy


"elsandalos" wrote in message
...
Cheers Tom.

Oddly i don't get the problem when using "=", even if the month and day

can
be flipped. I've just read around, and seen that people are using cdbl

when
feeding a date into the autofilter. I've got it fixed with that, and also
using your method.

still strikes me as odd though. Whats the difference between feeding
autofilter a criteria through VB and doing it manually on the worksheet?

Anyway - ta for the help :)

El.



"Tom Ogilvy" wrote:

ws.UsedRange.AutoFilter Field:=1, Criteria1:="<" & _
format(cdate("01/02/2005"),"mm/dd/yyyyy")

I would bet you have the problem even with "=" if the month and day can

be
flipped and still form a good date.

In VBA, you need to work with US formatted dates if you are going to

work
with strings, otherwise, work with date serial numbers.

--
Regards,
Tom Ogilvy


"elsandalos" wrote in message
...
I'm using VB to autofilter a number of worksheets using a criteria

entered
in
a textbox.


--------------------------------------------------------------------------
------
Sub Filter_Box3()

Dim ws As Worksheet
Dim crit As String
Dim agsheetname As String

crit = Sheet1.Filtertext2.Value

Application.ScreenUpdating = False

For Each ws In Worksheets
agsheetname = ws.Name
If agsheetname < "Guide" Then

ws.UsedRange.AutoFilter Field:=1, Criteria1:="<" & crit

End If

Next ws

Application.ScreenUpdating = True

End Sub


--------------------------------------------------------------------------
------

for some reason, when using < or the date has been flipped around

when i
check the autofilter settings on the worksheets, so that if crit =
01/02/2005, it gets changed to 02/01/2005. This does not happen when

using
=
in the criteria. Even when i hard code a date into the function like:


--------------------------------------------------------------------------
-----
ws.UsedRange.AutoFilter Field:=1, Criteria1:="<01/02/2005"


--------------------------------------------------------------------------
------

... it still gets flipped around.

Any ideas?

El.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Date flips around when using Autofilter in VB

yeah, sorry - i changed the variable from a string to date.

"Tom Ogilvy" wrote:

cdbl used with a date string such as

cdbl("01/23/2005")

won't work. so you must not be sending it a date string.

anyway, the difference is that one is done with VBA and one is done with
Excel. They are two different products and have different behaviors.

--
Regards,
Tom Ogilvy


"elsandalos" wrote in message
...
Cheers Tom.

Oddly i don't get the problem when using "=", even if the month and day

can
be flipped. I've just read around, and seen that people are using cdbl

when
feeding a date into the autofilter. I've got it fixed with that, and also
using your method.

still strikes me as odd though. Whats the difference between feeding
autofilter a criteria through VB and doing it manually on the worksheet?

Anyway - ta for the help :)

El.



"Tom Ogilvy" wrote:

ws.UsedRange.AutoFilter Field:=1, Criteria1:="<" & _
format(cdate("01/02/2005"),"mm/dd/yyyyy")

I would bet you have the problem even with "=" if the month and day can

be
flipped and still form a good date.

In VBA, you need to work with US formatted dates if you are going to

work
with strings, otherwise, work with date serial numbers.

--
Regards,
Tom Ogilvy


"elsandalos" wrote in message
...
I'm using VB to autofilter a number of worksheets using a criteria

entered
in
a textbox.


--------------------------------------------------------------------------
------
Sub Filter_Box3()

Dim ws As Worksheet
Dim crit As String
Dim agsheetname As String

crit = Sheet1.Filtertext2.Value

Application.ScreenUpdating = False

For Each ws In Worksheets
agsheetname = ws.Name
If agsheetname < "Guide" Then

ws.UsedRange.AutoFilter Field:=1, Criteria1:="<" & crit

End If

Next ws

Application.ScreenUpdating = True

End Sub


--------------------------------------------------------------------------
------

for some reason, when using < or the date has been flipped around

when i
check the autofilter settings on the worksheets, so that if crit =
01/02/2005, it gets changed to 02/01/2005. This does not happen when

using
=
in the criteria. Even when i hard code a date into the function like:


--------------------------------------------------------------------------
-----
ws.UsedRange.AutoFilter Field:=1, Criteria1:="<01/02/2005"


--------------------------------------------------------------------------
------

... it still gets flipped around.

Any ideas?

El.









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
Why I can't autofilter date (01-Jul-06 to 31-Jul-06) in Exel? elephant Excel Discussion (Misc queries) 1 August 9th 06 02:28 PM
frustrated with VBA select/activate and screen flips William DeLeo Excel Discussion (Misc queries) 8 June 13th 06 09:17 PM
F9 flips formulas between zero and correct value Arun Excel Discussion (Misc queries) 1 April 21st 06 02:29 PM
work sheet view flips horizontally Ross Excel Discussion (Misc queries) 3 November 2nd 05 04:06 AM
Multiple coin flips in a single cell igor eduardo küpfer Excel Worksheet Functions 7 September 13th 05 03:09 PM


All times are GMT +1. The time now is 12:30 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"