Vba to change a list of text data to dates?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have a sheet with data that's supposed to be dates but is recorded wrong I need a macro to turn it into dates.

So Column F hold what should be dates but they are written as just year month like this "2010-01"
2010-01
2010-05
2010-07
2010-11
2011-01
2011-02

<tbody>
</tbody>

So I want them all to be first of the month and an actual date in the order dd/mm/yyyy
so the first one would be "01/01/2010" etc

how can I do this?

Thanks

Tony
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi,

If you can confirm that column F has no blank row & starts in F1 you can use this :

Assuming you want first day of the month :

Code:
Sub verificaCNP()
    
On Error Resume Next

    nbr = Range("F1").End(xlDown).Row
    
    For Each cel In Range("F1:F" & nbr)
        
        y = Left(cel.Value, 4)
        m = Right(cel.Value, 2)
        cel.Value = DateSerial(y, m, 1)
    
    Next cel
    
 
End Sub
 
Last edited:
Upvote 0
Thank you LouisH, had to play around with it but just what i needed :)
 
Upvote 0

Forum statistics

Threads
1,215,334
Messages
6,124,321
Members
449,154
Latest member
pollardxlsm

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