PDA

View Full Version : Solved: Read in value to use as array size



frubeng
11-17-2010, 09:15 AM
Hello,

I want to declare an array such as:
MyArray(1 to N)

Where I read in N from the spreadsheet. The compiler tells me that N must be a 'Const' but in that case, i can't seem to let N read in a value from the sheet.

Any ideas?

Thanks!!

GTO
11-17-2010, 09:27 AM
Hi there,

Try ReDim:

Option Explicit

Sub exa()
Dim x As Long
Dim ary() As Long

x = 3

ReDim ary(1 To x) As Long

ary(1) = 23
ary(2) = 321
ary(3) = 213
End Sub

Hope that helps,

Mark

frubeng
11-17-2010, 10:22 AM
Perfect, thank you very much!