VB to change dates

superbob

New Member
Joined
Feb 9, 2010
Messages
37
Hi,

I've got some date fields in Excel 2007 which have swapped the days with the month for any date before 10/10/YYYY. I.e. 02/06/2010 is showing as 06/02/2010.
I need to update any date before 10/10/YYYY to swap the first to numbers with the next to numbers. Basically, swap days with months.

Any ideas?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try this formula,

Code:
=IF(A1 < DATE(2010,10,10),date(year(a1),day(a1),month(a1)),A1)

Adjust ranges to suit.
 
Upvote 0
Thanks but the year isn't always 2010 and I need to update the cells directly rather than creating another field.
 
Upvote 0
Have you checked the cell format?

Should that date be 6th feb or 2nd June? Bear in mind that different countries use different date formats, if your data is being imported it could be that the source is using mm/dd/yyyy while you're using dd/mm/yyyy. Excel will have no way of knowing which format is desired so will match it to your regional settings.

Seems strange that it's only wrong up to 10/10 though, normally happens on anything where the date could also be the month.
 
Upvote 0
OKay...my formula just needs a slight modification

=IF(A1 < DATE(YEAR(A1),10,10),date(year(a1),day(a1),month(a1)),A1)
 
Upvote 0
You could try selecting the dates, Data > Text to Columns, press Next twice, tick Date and select DMY then click Finish.
 
Upvote 0
Jasonb75

The cell format is correct. There's a rountine which is run that changes the date if the day is less than 10 or the month is less than 10. Have you seen something like this before?

Delaneyjm,

Thank you for the formula, I will only use this as a last resort due to having creating another field and also have to change the formula.

VoG,

THe solution seems to work but can I macro this to change the format is the day is less than 10 or the month is less than 10.

Cheers
 
Upvote 0
Not seen exactly this before, just an observation from copying anything with dates that's in a different format, for example when people post sample data here using Excel-Jeanie. My regional settings use Date format dd mm yyyy, meaning if the sample is in format mm dd yyyy the month and date get switched if the date is less that 13.

Can you give us more info on the routine that is doing this, Maybe it would be better to correct the problem at the source?
 
Upvote 0

Forum statistics

Threads
1,216,107
Messages
6,128,866
Members
449,475
Latest member
Parik11

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