Home > other >  Converting Text Date to Date VBA
Converting Text Date to Date VBA

Time:06-14

I have a date cell value which was extracted in this format 20220610. Is it possible to convert this to a date format e.g., 10 Jun 2022?

CodePudding user response:

You no need VBA. Try below formula-

=TEXT(DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2)), "dd mmm yyyy")

If you need VBA then try below function. You have to format resulting cell as proper date format or use TEXT() function.

Function MyDate(iDate As String) As Date
    MyDate = DateSerial(Left(iDate, 2), Mid(iDate, 5, 2), Right(iDate, 2))
End Function

enter image description here

  • Related