0

Anybody knows how to convert a month name into 3 letter abbreviation? For example, if the month is September, then it should return Sep only. I have been searching in the net but unfortunate enough to have the answer. Thanks!

3 Answers3

4

Try with below

Sub test()
    Dim a As String
    a = Format("11/10/2015", "MMM")
    MsgBox a
End Sub

or

Sub test()
    Dim a As String
    a = Format(Now(), "MMM")
    MsgBox a
End Sub

if you have the month name as variable then

Sub test()
    Dim a As String
    a = "February"
    MsgBox Mid(a, 1, 3)
End Sub
Karthick Gunasekaran
  • 2,697
  • 1
  • 15
  • 25
1

What will always work is to make your own function, e.g.:

Function Month2Mon(month) As String
    Select Case LCase(month)
    Case "january": Month2Mon = "Jan"
    Case "february": Month2Mon = "Feb"
    ...
End Function
Paul Ogilvie
  • 25,048
  • 4
  • 23
  • 41
1

You can also try this:

Sub Demo()
    Dim MonthName As String
    MonthName = "September"
    MsgBox Format(DateValue("01 " & MonthName & " 2012"), "MMM")
End Sub

This solution is derived from @SiddhartRout's answer from here.

Community
  • 1
  • 1
Mrig
  • 11,612
  • 2
  • 13
  • 27