• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

change date "m/d/yy h:mm" format to "dd/mm/yyyy hh:mm" using VBA

Mike Zagle

New Member
Hi All, I have been trying to change the format of the date with a vba code since " format cells" is not working for the current purpose. , I have tried to select and replace but it is time consuming with more than 8000 observations with different dates.
```

Code:
Sub changes()
   Dim trial As Variant
   Dim base() As String
   Dim i As Integer
  
      trial = ActiveSheet.Range("A3").Select
       i = ActiveSheet.Range("B3").Select
  
       base = Split(trial, "/")
    
      If Len(base(2)) = 2 Then
     i = base(1) & "/" & base(0) & "/" & base(2)
     End If
  
End Sub
``` I have tried this but it is not working... I am new to VBA and would like to have a code to convert my date. Thanks
 
Last edited by a moderator:
Hi Mike, and welcome to the forum. :awesome:

Before trying to use VB to split the data and put it back together, I would suggest using the native XL feature. It's somewhat hidden, but on the 3rd screen of the Text-to-columns tool (pick delimited on first, skip 2nd screen), is the option to re-interpret dates.

upload_2016-4-22_10-45-15.png

I'd suggest giving that a try first. If you need this as part of a larger macro, you could always record this action.
 
Back
Top