Hello Forum,
I am trying to identify month and year from a date in generic format so that :
1. The month value be changed to the name of the month.
2. Identify the last two digit values of the year.
3. Concatenate first 3 characters of month name, a hyphen and last 2 digits of year.
Please go through the attachment. MonthYear.xlsx. Column B is the function output.
Wrote a function for this purpose, but it is not working properly in some cases. Please go through the code:
Function MonthYear(D As String) As String
Dim m, y As String
m = Mid(D, 4, 2)
Select Case m
Case "01"
m = "Jan"
Case "02"
m = "Feb"
Case "03"
m = "Mar"
Case "04"
m = "Apr"
Case "05"
m = "May"
Case "06"
m = "Jun"
Case "07"
m = "Jul"
Case "08"
m = "Aug"
Case "09"
m = "Sep"
Case "10"
m = "Oct"
Case "11"
m = "Nov"
Case "12"
m = "Dec"
Case Else
m = "Invalid Month"
End Select
y = Right(D, 2)
MonthYear = m & "-" & y
End Function
Regards,
Sailaja
Bookmarks