0

Programming a macro in excel 2010 What am I doing syntactically that is causing the error?

Error message says:

Compile error: Expected: end of statement

Code:

Dim myArray = New String() {"A",  "B",  "C", ... continues to..."Z" } 
Community
  • 1
  • 1
  • possible duplicate of [Declare and Initialize String Array in VBA](http://stackoverflow.com/questions/19369132/declare-and-initialize-string-array-in-vba) – Ravi Yenugu Jun 27 '14 at 17:28

1 Answers1

1

looks like you are using some other language construct, try simply this (assumes you know in advance how long the array needs to be, and that you know in advance the values to assign to the array:

Dim myArray() As String

myArray = Split("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z", ",")

If you don't know the values in advance, the approach might need to be different using iteration/etc.

Note: arrays are typically base 0 in vba, this example makes it base 1.

David Zemens
  • 53,033
  • 11
  • 81
  • 130