DATE reversed when run Paste Special by VBA code

Hyakkivn

Board Regular
Joined
Jul 28, 2021
Messages
81
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone !
As the title, I got problem with paste special function when I copied data (table type) from 3rd party software (wrote in VB.net language with DATA store to an Access file) to excel.
Everything went well until it copied date. For example, the date is: 08 Oct 2021 (08/10/2021), after copy and paste special by macro, it become 10 August 2021 (10/08/2021)
But if I do it manually (Ctrl+C at software then right click and choose Paste Special on Excel), nothing wrong with that date.
Any help will be appreciated.
Best regard !!!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
VBA defaults all dates to US (mm/dd/yy) format, I've had problems with this before when I had to manipulate dates that are in UK (dd/mm/yy) format in vba but would have thought that copy and paste should work correctly.

If it's happening to all dates then I personally would use text to columns after parse the dates back to the correct format (integrated into the copy and paste code). Others may have different ways to fix it.
 
Upvote 0
Maybe set the numberformat to "dd/mm/yyyy" first.

For example

VBA Code:
Sub jec()
Range("A2").NumberFormat = "dd/mm/yyyy"
Range("B2").Copy
Range("A2").PasteSpecial xlPasteValues
End Sub
 
Upvote 0
Maybe set the numberformat to "dd/mm/yyyy" first.
That is a bad way to do it. Typically what will happen is that the month and day will be switched if the day is 12 or less but will still be a valid numeric date. Dates with a day of 13 or more will remain as original but will be in text format.

Text to columns can fix all dates at once when this happens but messing with cell formats before pasting can prevent this from working correctly.
 
Upvote 0
Then text to columns it is :)
 
Upvote 0
Maybe set the numberformat to "dd/mm/yyyy" first.

For example

VBA Code:
Sub jec()
Range("A2").NumberFormat = "dd/mm/yyyy"
Range("B2").Copy
Range("A2").PasteSpecial xlPasteValues
End Sub
I thought and tried this before. No help. The date still be reversed. Why don't we use just one date format only..brrrr. Let me try Jason's solution.
 
Upvote 0
I thought and tried this before. No help. The date still be reversed.
If you've already changed the format then text to columns may not work correctly. It would be best to clear the data and paste to cells with a 'General' format, then apply text to columns, selecting MDY from the date dropdown on the last tab.
 
Upvote 0
I've answered a similar question in this thread:
see it helps.
 
Upvote 0
I've answered a similar question in this thread:
see it helps.
I 've tried your code, but it do nothing. I think my problem is different from others. I copy data from 3rd party software, then paste to excel. And when "the macro copy and paste special date", it swaps day to month - month to day. All I can do is do copy paste special manually. ?
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,582
Members
449,039
Latest member
Arbind kumar

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