我正在创建一个宏,它将识别月份并将前3个字母和2个最后一个数字放入工作表名称.这是我到目前为止创建的:
例如Cells(9,1)
,每月的第一天(01/01/2016)
Dim mName(13) As Integer Dim ValDate As String Dim years As String Dim mcount As String mName(1) = January mName(2) = Febuary
...
mName(13) = December years = Right(Year(Cells(9, 1)), 2) '16 ValDate = mName(Month(Cells(9, 1))) 'macro says its 0, but it should be January) mcount = Left(ValDate, 3) Sheets(Sheets.Count).Name = ValDate & " " & years
宏的结果是"0 16"我的目标是"1月16日".
宏工作正常(没有错误)但是当ValDate字符串中有mName整数时,它总是显示"0".月函数可以正常工作,没有mName.
用双引号括起名称.
Dim mName(1 To 12) As String mName(1) = "January" '<~~~ double quotes ... mName(12) = "December" '<~~~ 12, not 13. There are only 12 months in a year