Friday, April 5, 2013

Format dates like 1st, March 2013 2nd March 2013 etc

If you want to format dates like 1st March 2013 , 2nd March 2013 ,etc . Try this macro



Sub fmt_dates()
    Dim Cell As Range
    Dim fmttext As String
    For Each Cell In Selection
        Select Case Day(Cell)
            Case 1, 21, 31:
                fmttext = """st"""
            Case 2, 22:
                fmttext = """nd"""
            Case 3, 23:
                fmttext = """rd"""
            Case Else:
                fmttext = """th"""
        End Select
        Cell.NumberFormat = "d" & fmttext & ", MMMM YYYY"
    Next Cell
End Sub



No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...