I am trying to write a month index to name converter. It must return the entire array if no arguments are passed, only the month name if a valid index is passed or a transposed vertical array if negative index is passed.
The first two cases are working good but when i pass -1
as an argument, it doesn’t return anything at all. I can pinpoint Application.Transpose
is not returning anything. So the cell is empty after function invocation.
Function MonthNames( Optional Mindex )
Dim Allnames As Variant
Allnames = Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" )
Select Case IsMissing( Mindex )
Case True
MonthNames = Allnames
Case False
Select Case Mindex
Case Is >= 1
monthval = ((Mindex - 1 ) Mod 12 )
MonthNames = Allnames( monthval )
Case Else
MonthNames = Application.Transpose( Allnames)
End Select
End Select
End Function
I have Option VBASupport 1
set on the top of the script.