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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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?
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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