changing date format

bobkasterop

New Member
Joined
May 10, 2018
Messages
6
Hey, so i have to change the date format in an excel sheet from yy-mm-dd to dd-mm-yy.
i tried using numberformat like this 'Range("A2", "A50000").NumberFormat = "dd-mm-yy"' but this doesnt change anything.
i also tried using format(Date,"dd-mm-yy") but this just sets the cell to have the date of today (from my computer)
i think that the reason for numberformat not working is that Excel doesnt really know which of the bits is yy which is dd and which is mm and therefore is thinking that they are allready in the right order.

my question is therefore:
how do i make excel now that right now it is in the order of yy-mm-dd? so that i aftwerwards can use numberformat.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Is your date an Excel date?

Change A2 to where your date is. Does this return TRUE?
Code:
=ISNUMBER(A2)
 
Upvote 0
if you do have dd mm yy problems then dd mmm yyyy is unmistakable
 
Upvote 0
Assuming your data are in A2:A50000 (change range to suit):
Code:
Sub ChangeDateFormat()
'Assumes initial format is yy-mm-dd and changes it to dd-mm-yy
Application.ScreenUpdating = False
Columns("B").Insert
With Range("B2:B50000")
    .Formula = "=RIGHT(A2,2)&""-""& Mid(A2, 4, 2) & ""-""&LEFT(A2,2)"
    .Value = .Value
End With
Columns("A").Delete
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
this does not work for me. it doesnt execute the formula it just turns the value of all the b cells to this "=RIGHT(A2,2)&""-""& Mid(A2, 4, 2) & ""-""&LEFT(A2,2)"
 
Upvote 0
Your data are not dates (numbers) they are strings. Did you try the macro in post #4 ?
 
Upvote 0
yes but it doesnt work for me. it just inserts this "=RIGHT(A2,2)&""-""& Mid(A2, 4, 2) & ""-""&LEFT(A2,2)" directly into the cells instead of executing the formula.
 
Upvote 0
this does not work for me. it doesnt execute the formula it just turns the value of all the b cells to this "=RIGHT(A2,2)&""-""& Mid(A2, 4, 2) & ""-""&LEFT(A2,2)"
I assume you are addressing me. That's happening because your column B is formatted as text. Here's a revision that may overcome that.
Code:
Sub ChangeDateFormat()
'Assumes initial format is yy-mm-dd and changes it to dd-mm-yy
Application.ScreenUpdating = False
With Columns("B")
    .Insert
    .NumberFormat = "General"
End With
With Range("B2:B50000")
    .Formula = "=RIGHT(A2,2)&""-""& Mid(A2, 4, 2) & ""-""&LEFT(A2,2)"
    .Value = .Value
End With
Columns("A").Delete
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This just inserts a new row in D and inserts "=RIGHT(A2,2)&""-""& Mid(A2, 4, 2) & ""-""&LEFT(A2,2)" into all the cells in that row...
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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