Filter Date via VBA - European Format

AECJohn

New Member
Joined
Jun 23, 2022
Messages
6
Office Version
  1. 2021
Platform
  1. Windows
This is my current script:

Sub FilterDateRange()
'
' FilterDateRange Macro
' Filter a date range
'
' Keyboard Shortcut: Ctrl+Shift+P
'

Range("I2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]"
Selection.AutoFill Destination:=Range("I2:I" & Range("B" & Rows.Count).End(xlUp).Row)
Range(Selection, Selection.End(xlDown)).Select
Range("I:I").Copy
Range("I:I").PasteSpecial Paste:=xlPasteValues
Range("L4:N4").NumberFormat = "MM/DD/YYYY"
Range("L4:N4").NumberFormat = "DD/MM/YYYY"


Set First_Cell = Worksheets("Sheet1").Range("A2")
Set Starting_Date = Range("L4")
Set Ending_Date = Range("M4")
Field = 9

First_Cell.AutoFilter Field:=Field, Criteria1:=">=" & Starting_Date, Operator:=xlAnd, Criteria2:="<=" & Ending_Date

Range("I:I").NumberFormat = "MM/DD/YYYY"

End Sub

I cannot get Excel to acknowledge that 01/06/22 is June 1st, it keeps defaulting to January 6th. I have even added lines of code specifying the date format, does not work.
It will acknowledge 25/05/22 as May 25th though... Any date that can be an North American date, it defaults to North American.

Any ideas?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try:
VBA Code:
First_Cell.AutoFilter Field:=Field, Criteria1:=">=" & CLng(Starting_Date), Operator:=xlAnd, Criteria2:="<=" & CLng(Ending_Date)
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,787
Members
452,942
Latest member
VijayNewtoExcel

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