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...
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

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?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,682
Messages
5,838,788
Members
430,569
Latest member
sbardelli

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