Date displayed in CSV file not the same as what is saved in the file

exce101

New Member
Joined
Jan 27, 2018
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a macro that exports data from an xlxm file into a single tab and saves it as a csv to enable upload into a system.

A particular date format in the source file has the date value as 01/01/9999 and displayed in that exact format i.e. dd/mm/yyyy. When the macro creates the csv file, this value is also exported as 01/01/9999 but displayed as 01-Jan-99 i.e. dd-mmm-yy however when the csv file is closed and reopened, the date changes to 01/01/1999 still displayed as 01-Jan-99.

Any idea why this would be the case or how to stop this?


Code as below:

Application.ScreenUpdating = False
Rows("4:150").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ChDir "C:\Uploads"
ActiveWorkbook.SaveAs Filename:= _
"C:\Upload " & Format(Range("h5"), "ddmmyyyy") & ".csv", FileFormat:=xlCSV, _
CreateBackup:=False
Range("H2:I150").NumberFormat = "dd-mmm-yy"
Range("AA2:AA150").NumberFormat = "dd-mmm-yy"
Range("AU2:AU150").NumberFormat = "dd-mmm-yy"
ActiveWorkbook.Save
Range("a1").Select
End Sub


Thanks in advance.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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