REPLACE function with dates

Riikka

New Member
Joined
Sep 10, 2002
Messages
5
My problem is about the REPLACE function. I'm creating macros, and there's a range of cells with dates in format dd/mm/yyyy (or dd.mm.yyyy). I should convert these to ddmmyyyy! Win XP doesn't let me use that date format directly (saw in Regional settings).

If I use REPLACE, so that "/" would replaced with "" (none), the result somehow is dd/mm/yy and not ddmmyyyy as it should be! I've tried formatting the cells to text, or custom, first, but it doesn't help. If I format the cells to text and then manually remove the /'s, that works, but it's not really useful, because I'm creating macros, and I should have a function which I could use there. Hope there's someone there who can help me...
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Try this:

Code:
Sub Test()
    If InStr(1, Selection.NumberFormat, "/") Then
        Selection.NumberFormat = "ddmmyyyy"
    End If
End Sub

For some reason on my machine (Win2000, Excel2000) formatting a date as dd/mm/yyyy results in a format of m/d/yyyy (per the Macro recorder), but it displays correctly.

So when I used:

Code:
If Selection.NumberFormat = "dd/mm/yyyy" Then

nothing happened. Strange?
 

Watch MrExcel Video

Forum statistics

Threads
1,123,334
Messages
5,601,012
Members
414,421
Latest member
tonybear1994

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
Top