Excel VBA类型不匹配错误将范围传递给数组 [英] Excel VBA Type Mismatch Error passing range to array

查看:324
本文介绍了Excel VBA类型不匹配错误将范围传递给数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检索工作表中的单元格数组的值(存储为数组而不是简单的单元格),但是由于某些原因,始终会遇到运行时错误13类型不匹配的情况。我读过有关类似问题的文章,但是其中许多似乎与数组类型错误(即NOT Variant类型)或静态大小有关。

I'm trying to retrieve the values of an array of cells in a worksheet (stored as an array rather than simple cells), but for some reason keep getting a Run-Time Error 13 Type Mismatch. I've read posts about similar issues, but many of those seem to have to do with either the array being of the wrong type (ie NOT Variant type), or being of static size.

以下是在调试中发生错误的相关行:

Here is the relevant line where the error occurs in debugging:

Dim SizeSelection() As Variant
SizeSelection = Workbooks("Wheels.xlsx").Worksheets("Test").Range("B1:W1")

我也尝试使用

Dim SizeSelection() As Variant
SizeSelection = Array(Workbooks("Wheels.xlsx").Worksheets("Test").Range("B1:W1"))

,但仍然出现相同的错误。除了上述2个常见错误之外,没有人知道为什么我会遇到类型不匹配的情况吗?我试过删除数组并将值存储在常规单元格中,但这没什么区别。

but still get the same error. Other than the 2 common mistakes mentioned above, does anyone have any idea why i would be getting a type mismatch? I've tried removing the array and storing the values in regular cells, but that made no difference.

哦,我应该提一下我要检索的数据在另一个工作簿中(尽管上面的代码应该清楚),并且该工作簿已经打开。

Oh, I should mention that the data I'm trying to retrieve is in another workbook (though that should be clear from the code above) and that workbook is already open.

谢谢!
Mike

Thanks! Mike

推荐答案

Dim SizeSelection()更改为变量 Dim SizeSelection As Variant ,您应该没问题。

这篇关于Excel VBA类型不匹配错误将范围传递给数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆