Excel Date Formatting
You can also use the TEXT()
function quite easily (Note: source data must be an excel date value)
TEXT(value, format_text)
where value
is the reference cell and format_text
is how you want to format the text- in your case dd/mm/yyyy.
Assuming:
A1 = 3/17/2013
A2 = 12/27/2013
In B1 & B2 simply input:
B1 = TEXT(A1, "dd/mm/yyyy")
B2 = TEXT(A2, "dd/mm/yyyy")
and the result should be
A B
3/17/2013 17/03/2013
12/27/2013 27/12/2013
Hope that helps.
UPDATED SUGGESTION IF WORKING WITH TEXT:
Split the string using mid()
, left()
and right()
functions then check to see if the month mm is 1 or 2 characters long using the LEN()
function. Finally concatenatr the string together using the & and / operators.
Try pasting this in B1, it should work fine:
=MID(A1,FIND("/",A1,1)+1,2)&"/"&IF(LEN(LEFT(A1,FIND("/",A1)-1))=1,0&LEFT(A1,FIND("/",A1)-1),LEFT(A1,FIND("/",A1)-1))&"/"&RIGHT(A1,4)
You can use the DATEVALUE function to convert the date strings into Excel data values, and then create a custom date format to display the date values in U.K. format.
Assuming that the first date string is in cell A1, the following function call will turn the string into a date value.
=DATEVALUE(A1)
You can create the custom format dd/mm/yyyy;@
by right-clicking on the cell, choosing Format Cells, Number, Custom and entering the format in the Type field.
Working with date values instead of date strings will allow you to change the displayed format without having to do string operations to rearrange the date elements. It will also make it possible to do date arithmetic, should that need arise.
Here is a sub that might help you. Using the QueryTables method, you can specify that Excel interpret certain columns of data as string.
Sub ImportExternalCSVAsText()
'
Dim sFileName As String
sFileName = Application.GetOpenFilename("CSV files, *.csv")
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & sFileName _
, Destination:=Range("$A$1"))
.Name = "CSV"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 2, 2) '2 denotes STRING
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
In the example, I imported a CSV file 3 columns wide, and specify that columns 2 and 3 contain String type data.
.TextFileColumnDataTypes = Array(1, 2, 2) '2 denotes STRING
If this method does not work, let me know. I have had to deal with this problem before (as a US contractor for UK contract job) and I'm pretty sure I have a few functions laying around that I used at the time.
This will bring all the values in as string.
You will most likely have to parse them because US date inputs like "12/30/2011" will fail the DATEVALUE()
function on your system Locale, and US date inputs like "07/05/2012" (July 5, 2012) would be interpreted as "May 7, 2012" by your locale.