Inconsistent Date format while copying Date Column

PrashanthKumar123

New Member
Joined
May 1, 2021
Messages
37
hi All - I have an excel tool that allows my users to upload a worksheet. One column in this sheet is Date (refer input), however once the user uploads the sheet into the tool, some Dates are ddmmyyyy and the rest as mmddyyyy. Not sure why this is inconsistent and looking to understand what to change in my code to get around this. any ideas welcome!

FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Excel Files (*.xls*),*xls")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(Filename:=FileToOpen, ReadOnly:=True)
Set src = OpenBook.Sheets(1)
src.UsedRange.UnMerge
lastrow = Application.WorksheetFunction.Max(src.Range("A" & src.Rows.Count).End(xlUp).Row, src.Range("B" & src.Rows.Count).End(xlUp).Row, src.Range("C" & src.Rows.Count).End(xlUp).Row)
datecolumn = 1
ThisWorkbook.Sheets.Add.Name = "Dsheet"

ThisWorkbook.Worksheets("Dsheet").Range(ThisWorkbook.Worksheets("Dsheet").Cells(1, 1), ThisWorkbook.Worksheets("Dsheet").Cells(lastrow, 1)).Value = src.Range(src.Cells(1, 1), src.Cells(lastrow, 1)).Value
ThisWorkbook.Worksheets("Dsheet").Range(ThisWorkbook.Worksheets("Dsheet").Cells(1, 1), ThisWorkbook.Worksheets("Dsheet").Cells(lastrow, 1)).NumberFormat = "DD-MM-YYYY"
OpenBook.Close False
End If


The input and output columns are as below.

Input Output
25/01/2021 25/01/2021
01/02/2021 02-01-2021
01/02/2021 02-01-2021
01/02/2021 02-01-2021
01/02/2021 02-01-2021
01/02/2021 02-01-2021
01/02/2021 02-01-2021
01/02/2021 02-01-2021
16/02/2021 16/02/2021
17/02/2021 17/02/2021
17/02/2021 17/02/2021
17/02/2021 17/02/2021
17/02/2021 17/02/2021
17/02/2021 17/02/2021
17/02/2021 17/02/2021
17/02/2021 17/02/2021
17/02/2021 17/02/2021
20/02/2021 20/02/2021
21/02/2021 21/02/2021
21/02/2021 21/02/2021
08/03/2021 03-08-2021
08/03/2021 03-08-2021
08/03/2021 03-08-2021
10/03/2021 03-10-2021
12/03/2021 03-12-2021
26/03/2021 26/03/2021
29/03/2021 29/03/2021
04/04/2021 04-04-2021
06/04/2021 04-06-2021
04/05/2021 05-04-2021
07/05/2021 05-07-2021
14/05/2021 14/05/2021
18/05/2021 18/05/2021
14/06/2021 14/06/2021
14/06/2021 14/06/2021
29/06/2021 29/06/2021
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Dave Patton

Well-known Member
Joined
Feb 15, 2002
Messages
5,029
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Try using Data Text to Columns for Date specify DMY

T202108b.xlsm
A
2Input Output
325-Jan-21
41-Feb-21
51-Feb-21
61-Feb-21
71-Feb-21
81-Feb-21
91-Feb-21
101-Feb-21
1116-Feb-21
1217-Feb-21
1317-Feb-21
1417-Feb-21
1517-Feb-21
1617-Feb-21
1717-Feb-21
1817-Feb-21
1917-Feb-21
2020-Feb-21
2121-Feb-21
2221-Feb-21
238-Mar-21
248-Mar-21
258-Mar-21
2610-Mar-21
2712-Mar-21
2826-Mar-21
2929-Mar-21
304-Apr-21
316-Apr-21
324-May-21
337-May-21
3414-May-21
3518-May-21
3614-Jun-21
3714-Jun-21
3829-Jun-21
1a
 

Forum statistics

Threads
1,148,146
Messages
5,745,051
Members
423,917
Latest member
Frank1931

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
Top