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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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