Reputation:
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!
Upvotes: 1
Views: 7315
Reputation: 11702
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.
Upvotes: 1
Reputation: 2713
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
Upvotes: 5
Reputation: 25266
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
Upvotes: 1