Machine UK/US date format in VBA

Masha92

Board Regular
Joined
Jan 27, 2019
Messages
51
Office Version
  1. 365
Hello everyone,

Hope you are all well and safe!

I was wondering if you can help me with this vba question (which might have been asked before but I couldnt find it)

I want to change yyyymmdd date format to the MACHINE date format. (whether it is dd/mm/yyyy or mm/dd/yyyy)

Can you please help me?

Many thanks!
Masha
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You can use DateSerial with Left, Right and Mid to extract the year, month and day parts.
 
Upvote 0
Hi Rorya,

This method will work with dd/mm/yyyy only correct?

Dateserial(left(X,4),mid(X,5,2),right(X,2)
 
Upvote 0
Possible alternative :
VBA Code:
Sub v()
With Selection
    Select Case Application.International(xlDateOrder)
        Case 0: .NumberFormat = "mm/dd/yyyy"
        Case 1: .NumberFormat = "dd/mm/yyyy"
        Case 2: .NumberFormat = "yyyy/mm/dd"
    End Select
End With
End Sub
 
Last edited:
Upvote 0
DateSerial takes Year, Month and Day arguments in that order, and will return an actual Date value, so there can be no confusion.
 
Upvote 0
Got you. Both solutions will work. I wasnot familiar with application.international. Thanks Rorya and footoo! Much appreciated
 
Upvote 0

Forum statistics

Threads
1,215,507
Messages
6,125,212
Members
449,214
Latest member
mr_ordinaryboy

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