Variant array -- Can't assign to array

D

dallascio1

I assign a range to a variant array in Windows and it works fine.

Here's the example code:

Dim varray() As Variant

varray = Range("D4:D8").Value

When I try to run the same macro on Excel OS X I get the error:

Can't assign to array.

I haven't been able to figure out the cause of this error.
 
J

JE McGimpsey

I assign a range to a variant array in Windows and it works fine.

Here's the example code:

Dim varray() As Variant

varray = Range("D4:D8").Value

When I try to run the same macro on Excel OS X I get the error:

Can't assign to array.

I haven't been able to figure out the cause of this error.

It's a syntax difference between VBA5 (MacXL) and VBA6 (WinXL 2000+).
Your code will fail in WinXL97, too.

In VBA6 you can assign an array of values to a variant array. In VBA5,
you can't.

However, you can assign an array to a variant, so you can use:

Dim varray As Variant
varray = Range("D4:D8").Value

which results in varray containing a two-dimensional array of values,
where

varray(1,1) = Range("D4").Value
varray(2,1) = Range("D5").Value

etc.
 
D

dallascio1

Thanks,

Your suggestion did allow me to compile the VB code and assign a range
to a variant.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top