在Excel 2010中,一切正常,但在Excel 2013中,发生错误“类型不匹配”。问题在于以下代码行(我尝试过的不同变体)。
startDate = startDateCell.Value
startDate = CDate(startDateCell.Value)
startDate = CDate(Format(startDateCell.Value, "short date"))
startDateCell的内容是一个字符串,例如“ 12.06.2016”
startDate是一个日期变量
是美国格式的日期吗?我认为不是基于您发布的时间。问题可能是vba将其识别为美国日期,并将13/1/2016解释为1/13/2016(使用英国逻辑),引用了第13个月,这会产生错误。
Function Convertings() As String
Convertings = Format(DateValue("13/1/2016"), "mm/dd/yyyy")
End Function
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句