VBA:multidimensional arrayinit中的溢出错误

我得到了这个代码bizzare溢出消息错误,我不明白为什么。 能否请你帮忙 ? 我在另一个VBA模块中使用完全相同的代码,它的工作原理。

Dim tab_base As Variant tab_base= Worksheets("Test").Range("A1:AL1492").Value 

谢谢,

伊斯梅尔

你必须在范围内有一些无效的单元格。 我主要怀疑一些格式为Date单元格,其值或者太大或者太小。

为了安全起见,获取独立于格式的数值,请使用推荐的.Value2 。 所以试试

 tab_base= Worksheets("Test").Range("A1:AL1492").Value2 

然后,将数组中的所有内容都作为string或数字(对于date:数字)。 您可以稍后将数字转换为date,但您也可以在之前检查错误。

例如,在将某个单元格转换为date之前,可以这样做:

 Dim d As Date On Error Resume Next d = tab_base(i, j) if Err.Number <> 0 Then ' invalid date, this was a cell causing overflow 

PS:检查例如,如果Err.Number = 6 ,这意味着你真的有一个date溢出(THX马特)