Wednesday 15 February 2012

EXCEL VBA Error: "Compile Error: Expected Array" -


Can someone help me?

I'm getting a compilation error (...: "expected array") when working with arrays in my Excel workbook.

Actually, I have a 'mother' array (2D, type type) and four 'baby' arrays (1d, double type). The called sub-routine creates publicly declared arrays that use my main macro for display purposes. Unfortunately, craps final Baby Array ( "compilation error: by required Arre") removes Strangely, if I do this last baby array ( "in order to end" - Declaration / definition), my second child The last line starts to end.

Here is my code:

  public Mother_Array (()) can double declared "version, BabyOne_Array (as others), BabyTwo_Array (), BabyThree_Array ( ), BabyFour_Array as variables and arrays Deputy MainMacro () 'goods call SunRaySubRoutine (x, y)' accessories range ( "blah") to = BabyOne_Array: range ( "blahblah") = BabyTwo_Array range ( "blahbloh" = BabyThree_Array: range ( "blahblue") = BabyFour_Array End sub sub SunRaySubRoutine (x, y) n = x * sheet ( "ABC"). range ( "A1"). value + 1 ReDim Mother_Array (18, N) version, BabyOne_Array (N), BabyTwo_Array (N) Double ReDim BabyThree_Array (A Not), BabyFour_Array (n) as Double "(I do things 2) i = 0 N BabyOne_Array (i) = Mother_Array (0, i) BabyTwo_Array (i) = Mother_Array BabyThree_Array (i) = Mother_Array (of 4, i) BabyFour_Array (i) = Mother_Array (6, i) Next End Sub   

I tried to declare all arrays as above, but no I have tried to give a separate name to BabyFor_Are () for the benefit, but there is no benefit.

What's really strange is that even if I make out the part of the book which makes the babyfour_array (), the array still has zero values ​​for each element

it is also slightly What is odd is that for the first time the Baby Array never gets out (though, once for a second time (maybe once in 30 times) was carried out.

BANDAID: Temporary OK as one, I Only publicly declares a fifth dummy array (which is not filled Or re-dimensioned) This fifth array has no real use other than "compiled error: expecting array" to deceive the system.

alias

Do anyone know what this "compilation error: expected array" problem is with Excel VBA?

In your global declaration, you are declaring the last baby array as the only double . You declared it as the arrays of the first three. Sector are variants . But Upastrati at you as another three forms Redmisn Baby, and let's see the four as doubles.

Check it out and scroll down "Focus on a declared variable with a blurred statement".

When you declare something like this in VBA:

  dim x, y, z as long   

only z Is a long , remaining differences . The correct form is:

Dim X is long, long as Y, long Z (or double arrow in your case).

You can see that this will be the reason for the behavior you described, i.e. the last one, but not the other.

No comments:

Post a Comment