vba range.replace not setting date format properly

Mushy peas

New Member
Joined
Jun 14, 2023
Messages
27
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have a range (let's call it the A column) that has dates in this format: dd.mm.yyyy so I want to change the format to short dates d/m/yyyy

Instead when I use range.replace, it takes the values as if it is in the mm/dd/yyyy format. How do I replace it.


VBA Code:
Sub format_dates()
    Sheet1.Columns(1).Replace ".", "/"
End Sub
 
Last edited by a moderator:
You could try TTC:

Code:
    Sheet1.Range("A:A").TextToColumns Destination:=Sheet1.Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 4), TrailingMinusNumbers:=True

for example.
 
Upvote 0
Solution

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
You could try TTC:

Code:
    Sheet1.Range("A:A").TextToColumns Destination:=Sheet1.Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 4), TrailingMinusNumbers:=True

for example.
Omg, that somehow worked. Thanks so so much. Though may I ask how was TTC able to recognise the format?
 
Upvote 0
The fieldinfo argument tells it that column 1 is a date in DMY order.
 
Upvote 0

Forum statistics

Threads
1,215,193
Messages
6,123,566
Members
449,108
Latest member
rache47

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