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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try:
VBA Code:
First_Cell.AutoFilter Field:=Field, Criteria1:=">=" & CLng(Starting_Date), Operator:=xlAnd, Criteria2:="<=" & CLng(Ending_Date)
 
Upvote 0

Forum statistics

Threads
1,214,566
Messages
6,120,262
Members
448,953
Latest member
Dutchie_1

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