Consulting

Results 1 to 3 of 3

Thread: Solved: Read in value to use as array size

  1. #1
    VBAX Regular
    Joined
    Apr 2009
    Posts
    59
    Location

    Solved: Read in value to use as array size

    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!!

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    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

  3. #3
    VBAX Regular
    Joined
    Apr 2009
    Posts
    59
    Location
    Perfect, thank you very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •