Personal Macro to replace selection value

Paulo_3456

New Member
Joined
Jul 25, 2018
Messages
15
Hello everyone,

I am trying to do a very simple macro to replace date formats from MM/DD/YYYY to DD/MM/YYYY using a macro that I could use with some shortcut on my current selection on Excel :

Code:
Sub dateus_fr()

Dim date_us As String
Dim date_fr As String
Dim replace1 As String


date_us = Selection.Value
date_fr = Right(Left(date_us, 5), 2) & "/" & Left(date_us, 2) & "/" & Right(date_us, 4)


Selection.Offset(0, -1).Select
Selection.Offset(0, 1).Select


Selection.Value = date_fr


End Sub

When I execute this step by step, formula seem to work with date_fr being the right value I want but nothing happens to the cell when I execute the macro.

Does it have to do something with the cell format ?

Thank you for your help !
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You could instead select the column, Data > Text to columns, Next, Next, Date: DMY
 
Upvote 0
Works with both. If I enter 31/1/2019, it's a string with my regional settings, and it converts just fine to 1/31/2019.
 
Upvote 0
If the "dates" are MM/DD format in text to columns select MDY
 
  • Like
Reactions: shg
Upvote 0
No worries, I'm used to converting US dates to UK dates.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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