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!
Asked
Active
Viewed 5,948 times
3 Answers
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
-
What if I have a variable that equates to the name of the month? – May 02 '16 at 10:14
-
@ramedju: `Mid(monthNameVariable, 1, 3)` – shahkalpesh May 02 '16 at 10:15
-
@shahkalpesh what is the use of MID ? and 1 and 3? – May 02 '16 at 10:17
-
1@ramedju: `Mid` is a function that takes a string and extracts part of it. In this case, it is extract 3 characters from position 1. – shahkalpesh May 02 '16 at 10:18
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
-
3Too tricky?? What do you mean? Will always do as you want. You can change `month` for a number if you like – Paul Ogilvie May 02 '16 at 10:19