VBA Code to Convert MM.DD.YYYY To DD.MMM.YYYY in Excel

Complete Excel VBA Course

In different parts of the world, there are different languages spoken and written. With this, a VBA programmer also faces language related issues while writing a VBA program. Here is a common date related problem solved which converts a date written in MM.DD.YYYY format into Excel standard date.

VBA Code to Convert MM.DD.YYYY to DD.MMM.YYYY in excel

VBA Code to Convert MM.DD.YYYY To DD.MMM.YYYY in Excel : CODE

'This function converts a date from MM.DD.YYYY to system date format
Public Function ConvertToDate(strInputDate As String) As Date
    'Variable Declaration
    Dim iMonth As Integer
    Dim iDay As Integer
    Dim lYear As Long
    'Get month from first 2 digits
    If IsNumeric(Left(strInputDate, InStr(1, strInputDate, ".") - 1)) = True Then
        iMonth = Left(strInputDate, InStr(1, strInputDate, ".") - 1)
        ConvertToDate = Null
        Exit Function
    End If
    'Get day from input date
    If IsNumeric(Mid(strInputDate, InStr(1, strInputDate, ".") + 1, 2)) = True Then
        iDay = Mid(strInputDate, InStr(1, strInputDate, ".") + 1, 2)
        ConvertToDate = Null
        Exit Function
    End If
    'Get year from last 4 digits
    If IsNumeric(Right(strInputDate, 4)) = True Then
        lYear = Right(strInputDate, 4)
        ConvertToDate = Null
        Exit Function
    End If
    'Create a complete date and return the value
    ConvertToDate = CDate(iDay & "-" & MonthName(iMonth) & "-" & lYear)
End Function

To Convert the Date Format use this code in your Excel file, follow the below steps

1. Open an Excel file
2. Press Alt+F11
3. Insert a Module (Insert>Module) from menu bar
4. Paste the code in the module
5. Now write ConvertToDate formula in a cell and select the cell which contains a date in MM.DD.YYYY format

6. You may get the converted date in number format like below
7. To change the date format into the desired format, right-click on the cell and select ‘Format Cells…’

Complete Excel VBA Course

8. In the ‘Number’ tab, click on ‘Date’ category and select the format type you want to display (here I have selected DD-MMM-YYYY format)

9. Done, your date is converted. You can drag the formula to other cells as well

Download Practice File for Free

To help you practice this code, we have made this code available through practice file. Click on the below link to download the practice file.

Recommended Articles

Excel VBA Course : Beginners to Advanced

We are offering Excel VBA Course for Beginners to Experts at discounted prices. The courses includes On Demand Videos, Practice Assignments, Q&A Support from our Experts. Also after successfully completion of the certification, will share the success with Certificate of Completion

This course is going to help you to excel your skills in Excel VBA with our real time case studies.

Lets get connected and start learning now. Click here to Enroll.

Secrets of Excel Data Visualization: Beginners to Advanced Course

Here is another best rated Excel Charts and Graph Course from ExcelSirJi. This courses also includes On Demand Videos, Practice Assignments, Q&A Support from our Experts.

This Course will enable you to become Excel Data Visualization Expert as it consists many charts preparation method which you will not find over the internet.

So Enroll now to become expert in Excel Data Visualization. Click here to Enroll.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *