Dates randomly chaning format (VBA)

JamesW

Well-known Member
Joined
Oct 30, 2009
Messages
1,197
Hi guys,

I have a spreadsheet which is populated by an SAP report. I made a macro to make changes to the sheet and make it look pretty etc.

All works well, apart from the dates seem to switch to US format randomly:

07.02.2011 changes to 02/07/2011
01.05.2011 changes to 05/01/2011
15.08.2011 stays the same (but with /'s)

Here's the problematic bit of my code:

Code:
        With Range("F:F")
            .Replace What:=".", Replacement:="/" 
            .NumberFormat = "dd/mm/yyyy"
        End With
Why doesn't that do what it's supposed to?! Removing .NumberFormat makes no difference aswell.

The original dates are stored as Text when they are pulled from SAP (Not sure if this would change anything).
 
Were the cells formatted explicitly as Text originally? What are your regional settings for dates?
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Basically, I pull the report from SAP and they are set as TEXT format by default.

My regional settings are English (UK).
 
Upvote 0
What if you move the NumberFormat line above the other lines?
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

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