CAN'T CHANGE DATE FORMAT

mergim

New Member
Joined
Nov 24, 2020
Messages
49
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,

For some reason I cannot change the date format for my values (see picture). The cells marked with yellow are in US format, and the green ones are in European format. I have tried everything to format the values, so I have one type of format (European). I have tried to change format via "Ctrl + 1", and then choosing the European format "DD/MM/YYYY), "Text to Columns", replace the "/" with "-", added a "0" before the date, e.g. 05/23/2022, and not 5/23/2022, still nothing works. It seems like there is a glitch. I have even tried with Power Query.

Does anyone know how to fix this ?

Thanks in advance!

1662979036352.png

F
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
It looks like your data is entered as text instead of date.
Try this code:
If the middle number is > 12, then it will swap the day & month.
Data in col A.
VBA Code:
Sub flipDate()
Dim x, tx As String
Dim r As Range
Application.ScreenUpdating = False
For Each r In Range("A2", Cells(Rows.Count, "A").End(xlUp))
    tx = Replace(r.Text, "-", "/")
    x = Split(tx, "/")
    If UBound(x) = 2 Then
        If CLng(x(1)) > 12 Then
            r.Value = DateSerial(x(2), x(0), x(1))
        Else
            r.Value = DateValue(r.Text)
        End If
    End If
Next
Application.ScreenUpdating = True

End Sub

Example:
Book1
A
1DATE
201/03/2023
31/23/2022
42-3-2013
52-20-2012
Sheet4

result:
Book1
A
1DATE
201/03/2023
323/01/2022
402/03/2013
520/02/2012
Sheet4
 
Upvote 0
Solution
It looks like your data is entered as text instead of date.
Try this code:
If the middle number is > 12, then it will swap the day & month.
Data in col A.
VBA Code:
Sub flipDate()
Dim x, tx As String
Dim r As Range
Application.ScreenUpdating = False
For Each r In Range("A2", Cells(Rows.Count, "A").End(xlUp))
    tx = Replace(r.Text, "-", "/")
    x = Split(tx, "/")
    If UBound(x) = 2 Then
        If CLng(x(1)) > 12 Then
            r.Value = DateSerial(x(2), x(0), x(1))
        Else
            r.Value = DateValue(r.Text)
        End If
    End If
Next
Application.ScreenUpdating = True

End Sub

Example:
Book1
A
1DATE
201/03/2023
31/23/2022
42-3-2013
52-20-2012
Sheet4

result:
Book1
A
1DATE
201/03/2023
323/01/2022
402/03/2013
520/02/2012
Sheet4
Hello,

The value is set as a date and not a text...
The code helps! Thanks a lot!!
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,214,865
Messages
6,121,988
Members
449,060
Latest member
mtsheetz

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