Date Formatting (e.g. 050914) into excel formula

killpaddy

Board Regular
Joined
Jul 31, 2012
Messages
52
Hi,

How would you get a vba defined string e.g. "050914" to be ouput in a cell as "05/09/2014" (or just "05/09/14")

It must be classed as an actual date, not just a string in the cell for sorting and ordering etc.

Thanks in advance.
 
Thanks, I used your formula as a basis, but I had to execute it in VBA, not excel formulas. All the extra functions, such as Trim() and Str() were needed to get the string formatting correct. Chr(34) is the speech marks (") character code which is needed to write " into the string when coding a formula input in vba.

I formatted the destination cells as a Date (*dd/mm/yyyy) manually and it worked.

Code:
DateStr = "090914"
With Range("A1") 
    .formula = "=DATEVALUE(" & Chr(34) & Trim(Str(left(DateStr, 2))) & "/" & _
        Trim(Str(Mid(DateStr, 3, 2))) & "/20" & Trim(Str(Right(DateStr, 2))) & Chr(34) & ")"
End With

Output: '=DATEVALUE("09/09/2014")'
 
Upvote 0

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