+ Reply to Thread
Results 1 to 3 of 3

Declare an array with variable size

Hybrid View

  1. #1
    Registered User
    Join Date
    05-05-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Declare an array with variable size

    I need to create an array with a variable as it size

    For instance:

    Dim nSize as Integer
    
    nSize = 4
    
    Dim nArray(nSize) as Integer
    But this doesn't work, I get an error: "Constant expression required"

    Is there anyway that I can do this?
    Last edited by gtmeloney; 05-07-2009 at 02:44 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Declare an array with variable size

    See the ReDim statement. And you should always specify both upper and lower bounds of arrays as a matter of good practice.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Declare an array with variable size

    Hi gtmelony,

    The following works for me:
    Dim nSize As Integer, nArray()
    nSize = 4
    ReDim nArray(nSize)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1