I'm using an app that exports certain data to a CSV format. The date column, however, is not properly format in the raw data and contains unnecessary trailing characters for the year, which prevents Excel from interpreting it correctly once imported.
If I manually run Find and Replace on the column, the values are automatically recognized as dates. If I record the operation as a macro, however, and run it again, the trailing character is removed, but the data in the column is retained as a text, not as a date.
Here's the VBA code:
Sub formatDate()
Columns("A:A").Select
Selection.Replace What:=" г.", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
The regional format for a date is DD.MM.YYYY
. Also, if I simply edit any of the resulting cells (F2) and hit Enter without anything else, Excel switches to the proper format.
Sample data:
4 март 2017 г.
4 март 2017 г.
3 март 2017 г.
1 март 2017 г.
28 февруари 2017 г.
27 февруари 2017 г.
27 февруари 2017 г.
26 февруари 2017 г.
26 февруари 2017 г.