Autofilter with International Dates

Danl8619

New Member
Joined
Sep 21, 2009
Messages
4
Hi all,

I've created a macro that autofilters everything within the next 7 days of the current date along with several other criteria. It works perfectly on my computer in the US, but my UK counterpart seems to come up with incorrect rows. My guess is that it is a date formatting issue, but I'm not sure how to get around the problem. I have posted the macro below.

Code:
Private Sub Upcoming_Bids_Click()

Dim MyDate As String
Dim MyDatePlus As String

MyDate = Now()
MyDatePlus = DateAdd("d", 7, Now())

ActiveSheet.Unprotect

Selection.AutoFilter Field:=1, Criteria1:="=Propose to Bid", Operator:=xlOr, Criteria2:="=Propose to Re-Bid"
Selection.AutoFilter Field:=21, Criteria1:="=PLC", Operator:=xlOr, Criteria2:="=SBU"
Selection.AutoFilter Field:=14, Criteria1:=">=" & CStr(MyDate), Operator:=xlAnd, Criteria2:="<=" & CStr(MyDatePlus)

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
    False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
    AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
    :=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
    AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
    AllowUsingPivotTables:=True


End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try it with your variables as long rather than string:

Code:
Private Sub Upcoming_Bids_Click()
Dim MyDate As Long
Dim MyDatePlus As Long
MyDate = Date
MyDatePlus = DateAdd("d", 7, Date)
ActiveSheet.Unprotect
Selection.AutoFilter Field:=1, Criteria1:="=Propose to Bid", Operator:=xlOr, Criteria2:="=Propose to Re-Bid"
Selection.AutoFilter Field:=21, Criteria1:="=PLC", Operator:=xlOr, Criteria2:="=SBU"
Selection.AutoFilter Field:=14, Criteria1:=">=" & MyDate, Operator:=xlAnd, Criteria2:="<=" & MyDatePlus
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
    False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
    AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
    :=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
    AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
    AllowUsingPivotTables:=True

End Sub

Dom
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top