+ Reply to Thread
Results 1 to 5 of 5

Compile error: Expected Array

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    154

    Compile error: Expected Array

    Hi - I am getting a "Compile error: Expected Array" for the below code:

    Sub ListSheetsinArray()
    
    'List Sheets into an array
        Dim SheetArray As Integer
        Dim sCount As Integer
        Dim i As Integer
        
            sCount = Sheets.Count
        
            ReDim SheetArray(1 To sCount) As Integer
        
            For i = 1 To UBound(SheetArray)
    
                Cells(i, 1) = Sheets(i).Name
            Next i
    
    
    End Sub
    I feel like there is a simple thing I am missing, but can't figure it out. Any help is appreciated. Thanks
    pls click the star if you liked my answer!

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

    Re: Compile error: Expected Array

    This will compile and run.
    Sub ListSheetsinArray()
    
    'List Sheets into an array
        Dim SheetArray() As Integer
        Dim sCount As Integer
        Dim i As Integer
        
            sCount = Sheets.Count
        
            ReDim SheetArray(1 To sCount) As Integer
        
            For i = 1 To UBound(SheetArray)
    
                Cells(i, 1) = Sheets(i).Name
            Next i
    
    
    End Sub
    Not sure you need an array though if you just want to put the sheet names in cells.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    154

    Re: Compile error: Expected Array

    Thanks. I wanted to put the values into the array. This worked. Thanks

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

    Re: Compile error: Expected Array

    That code doesn't put any values in the array.

  5. #5
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    154

    Re: Compile error: Expected Array

    I know - I updated it

            For i = 1 To UBound(SheetArray)
    
                SheetArray(i) = Sheets(i).Name
            Next i

+ 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] Compile error: expected array
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2015, 04:06 AM
  2. [SOLVED] Compile Error - "Expected array "- when declaring a string variable??
    By wazimu13 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-09-2013, 03:20 PM
  3. Compile Error: Expected End With
    By Robert110 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-14-2013, 07:14 AM
  4. [SOLVED] Help with Compile Error: Expected Array
    By g8r777 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-05-2012, 11:44 AM
  5. Compile Error: Expected Array
    By abfrempong in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-13-2012, 02:35 AM
  6. Compile Error - Expected Array
    By AccountantCost in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2009, 02:34 PM
  7. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 PM

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