Hi All
I have been getting some code together which looks at a data tab;e and extracts between 2 date ranges.
My issue is the data in the rawdata is in DDMMYYYY - when the msgbox pops up and dates are entered the search results revert the dates its searching for to MMDDYYYY.
Any ideas on how i can force a DDMMYYYY?
code for reference
I have been getting some code together which looks at a data tab;e and extracts between 2 date ranges.
My issue is the data in the rawdata is in DDMMYYYY - when the msgbox pops up and dates are entered the search results revert the dates its searching for to MMDDYYYY.
Any ideas on how i can force a DDMMYYYY?
code for reference
Code:
Sub Daterangegrap()
'Disabling screen updates
'Application.ScreenUpdating = False
'Declaring two variables of Date data type
Dim StartDate, EndDate As Date
'Declaring variable for worksheet object
Dim MainWorksheet As Worksheet
'User inputs for date range
On Error Resume Next
StarDate = Format(Date, "DD/MM/YYYY")
StartDate = InputBox("Start Date")
If StartDate = 0 Then Exit Sub
If Not IsDate(StartDate) Then
MsgBox "Invalid date"
Exit Sub
End If
EndDate = Format(Date, "DD/MM/YYYY")
EndDate = InputBox("End Date. Must be greater than " & Format(StartDate, "ddd d mmm yyyy"))
If EndDate = 0 Then Exit Sub
If Not IsDate(StartDate) Then
MsgBox "Invalid date"
Exit Sub
ElseIf StartDate > EndDate Then
MsgBox "Start date greater then end date"
Exit Sub
End If
'Initializing worksheet object with "RawData" worksheet
Set MainWorksheet = Worksheets("RawData")
'Activating the worksheet object
MainWorksheet.Activate
'Sorting the data by date in column A in ascending order
Range("A1").CurrentRegion.Sort _
key1:=Range("A1"), order1:=xlAscending, _
Header:=xlYes
'Filter the data based on date range between starting date and end date
Range("A1").CurrentRegion.AutoFilter Field:=1, Criteria1:= _
">=" & StartDate, Operator:=xlAnd, Criteria2:="<=" & EndDate
'Copy the filter data
ActiveSheet.AutoFilter.Range.Copy
'Inserting new worksheet after the last worksheet in the workbook
Worksheets.Add after:=Worksheets(Worksheets.Count)
'Pasting the copied data
ActiveSheet.Paste
'Auto adjusting the size of selected columns
Selection.Columns.AutoFit
Range("A1").Select
'Activating the "RawData" sheet
MainWorksheet.Activate
'Removing filter from the worksheet which we applied earlier
Selection.AutoFilter
Sheets("Macro").Activate
End Sub
Last edited by a moderator: