我正在尝试使用工作表的名称创建验证列表.第一部分我在一个数组上添加每个工作表的名称(表格类似于"2018年1月","2018年2月"等),第二部分通过使用逗号分隔符连接数组的每个部分来创建List.
问题是ValidationList将我的字符串转换为"2018年1月"到日期格式"Jan-18".我不能继续我的代码,因为不尊重表名...
这是我的代码:
Sub RefreshMonth()
Dim xsheet as Worksheets
Dim monthList(20) As String
Dim valList As String
''' This part add every sheet names on an array and work well '''
i = 0
For Each xsheet In ActiveWorkbook.Sheets()
If xsheet.Name Like "*20*" Then
monthList(i) = xsheet.Name
i = i + 1
End If
Next xsheet
'This part create the validation list, where the unwanted conversion happend '''
With Range("B1").Validation
.Delete
.Add Type:=xlValidateList, _
Formula1:=Join(monthList, ",")
End With
Run Code Online (Sandbox Code Playgroud)
在这里,我的ValidationList在代码运行后使用不需要的转换的sheetname作为日期格式:

我尝试使用CStr()甚至在join()之后重新执行字符串转换,但是现在我没有找到任何工作. …