+ Reply to Thread
Results 1 to 4 of 4

Declaration Issues with Array - Expected End of Statement

Hybrid View

  1. #1
    Registered User
    Join Date
    07-16-2018
    Location
    Utah, United States
    MS-Off Ver
    17
    Posts
    4

    Declaration Issues with Array - Expected End of Statement

    I am new to arrays and keep having the same issue with any array I declare. For instance, the below code returns the error "compile error: Expected: end of statement". What am I doing wrong? I tried restarting my computer, and starting a brand new module, but to no avail.


    Sub somesub()

    Dim numbers = New Integer() {1, 2, 4, 8}

    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Declaration Issues with Array - Expected End of Statement

    You can't declare arrays like that in VBA.

    There are various options for declaring/populating arrays, this is perhaps the simplest.
    Dim numbers As Variant
    
        numbers = Array(1,2,4,8)
    If posting code please use code tags, see here.

  3. #3
    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: Declaration Issues with Array - Expected End of Statement

    Declarations don't work that way in VBA.

    dim numbers(1 to 4) as integer
    
    numbers(1)=1
    numbers(2)=2
    ...
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    07-16-2018
    Location
    Utah, United States
    MS-Off Ver
    17
    Posts
    4

    Re: Declaration Issues with Array - Expected End of Statement

    Thanks. Is there a way to declare a two (and three) dimensional array using only one line of syntax?

    It was done with
    Dim numbers As Variant
    
        numbers = Array(1,2,4,8)
    Can it be done with

    Dim numbers2(1, 1) As Variant

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Inserting a Function Into Array Declaration
    By Bobby Smith in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-17-2016, 09:00 AM
  2. Debug Error Expected Array: Highlights my UBound statement
    By CRIMEDOG in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-07-2015, 05:05 AM
  3. compile error expected line number statement end statement
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2014, 10:12 AM
  4. Replies: 4
    Last Post: 05-16-2012, 05:33 PM
  5. passing a variable to an array declaration
    By labogola in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-09-2012, 04:10 AM
  6. doctype declaration issues in xml
    By insularutopia in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-24-2008, 02:03 AM
  7. Array dimension declaration
    By yellephant in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-29-2007, 08:44 AM

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