简体   繁体   中英

VBA assign a range to an Array from different sheet

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 eg

Dim flArr() as variant 
flArr = Sheets("xxx").range(A1:A10)

This gives me an error. any workaround?

Thanks

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

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM