VBA将范围分配给来自不同工作表的数组 [英] VBA assign a range to an Array from different sheet
问题描述
我有两个不同的工作表,我必须将这两个工作表中的2个范围分配给两个不同的数组,但是问题是我无法在范围之前指定工作表,例如
I have two different sheets and i have to assign 2 ranges from these two sheets to two different array but the problem is i can not specify a sheet before range for e.g
Dim flArr() as variant
flArr = Sheets("xxx").range(A1:A10)
这给了我一个错误。有什么解决方法?
This gives me an error. any workaround?
谢谢
推荐答案
看看两者之间的区别代码和我的。删除变量变量后的括号,让excel找出它是一个数组。另外,您还需要在引号中包含范围,并指定要使用该范围中的值。
Look at the differences between your code and mine. Remove the parenthesis after your variant variable, let excel figure out it is an array. Also you need to include the range in quotations and specify that you want the values from the range.
Dim flArr As Variant
flArr = Sheets("xxx").Range("A1:A10").Value
希望这能对您有所帮助:)
Hope this helps :)
您也可以这样做一些不太常见的构造,但这会很尴尬。
You could also do some less common construction as this, but it will be just awkward.
Dim arr() As Variant
ReDim arr(1 To 10)
arr() = Sheets("xxx").Range("A1:A10").Value
希望这会有所帮助
这篇关于VBA将范围分配给来自不同工作表的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!