Excel dimensionar valores para una matriz post compilar vba

i want to be able to initialize an array to store the values of a conversion. but i don't know how many values there will be until compile time so i want the range to go from


1 to <some expression>

namely i want it as

Dim Colvals(1 To Len(EndColumn)) As Integer

but when the code is sent to compile it throws

Constant Expression required

any idea how to do it? i really don't want to limit the versatility of the program by forcing the specification of the range.

preguntado el 27 de agosto de 11 a las 19:08

1 Respuestas

You want to redimension your array using a Redim statement:

Dim Colvals() As Integer
ReDim Colvals(1 To Len(EndColumn))

It seems strange that it requires a Constant for the Dim and not the Redim, but it's true.

Respondido 28 ago 11, 00:08

+1: ReDim would be the way! As a note to OP, you should use LONG instead of INTEGER. Excel and VBA will work with Long by default, plus you don't want to run into a situation where you have gone over the bounds of Int. - Aevanko

I second Issun's statement about using Long. - Doug Glancy

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.