A column has a list of dates, some as [Date] Format and others as [General]

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
794
Office Version
  1. 365
Platform
  1. Windows
I'm looking for a VBA way to convert these troublesome dates.

I have a range of dates from January to December, however there are two rogue dates placed in that reoccur a couple hundred times each.

These dates are 31/01/2019 and 28/02/2019 - these are mixed in with actual date-formatted cells as 31/02/2019 and 28/02/2019 - on the surface they look identical however they aren't counted the same way in Excel.


I wrote a macro that selected the whole column, converted the whole thing to date, but this didn't change anything. The cell format changed but the contents were very much still text. So I then added a feature onto the macro that was something like:

Code:
Cells(activecell.row, "G").value = cells(activecell.row, "G").value

This worked, but it took a really very long time.

I'm having trouble with generic VBA codes that convert text to date because some dates actually are formatted as a date.


Any help? Thanks.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You should be able to fix that column with a simple Text to Columns. Just go to Step 3 and choose the Date option of DMY (be sure NOT to actually delimit any of your data).
That should convert those Text entries to dates, and leave your other date values as-is.

If you turn on your Macro Recorder. and record yourself performing the Text to Columns, you will have VBA code that will do what you want.
 
Last edited:
Upvote 0
You should be able to fix that column with a simple Text to Columns. Just go to Step 3 and choose the Date option of DMY (be sure NOT to actually delimit any of your data).
That should convert those Text entries to dates, and leave your other date values as-is.

If you turn on your Macro Recorder. and record yourself performing the Text to Columns, you will have VBA code that will do what you want.

Worked perfectly, you're a star!
 
Upvote 0

Forum statistics

Threads
1,216,739
Messages
6,132,438
Members
449,728
Latest member
teodora bocarski

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