+ Reply to Thread
Results 1 to 5 of 5

need help with error : compile error expected array

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-02-2017
    Location
    uk
    MS-Off Ver
    2010
    Posts
    104

    need help with error : compile error expected array

    I am trying to do a lookup function but it does not compile error occurs at this line:

    ReDim myarr(last_row)
    Could someone please help?

    Function look(a As String) As Integer  'a is string looking up in cell
    
    Dim myarr As String
    Dim index As Long, row_index As Long, i As Integer
    row_index = 2
    Dim last_row As Integer
    
    last_row = lookup.Range("d2").End(xlUp).Row
    
    MsgBox last_row
    
    ReDim myarr(last_row) 'redefine dimensions of array since have  last row
    
        For i = 1 To last_row
        
                myarr(index) = lookup.Cells(row_index, 4).Value 'col D string values stored in array
                    
                        If a = myarr(index) Then
                            look = lookup.Cells(row_index, 3).Value
                            
                            MsgBox look
                            
                        Else
                        End If
                row_index = row_index + 1
                index = index + 1
        Next
    
    End Function

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    82,837

    Re: need help with error : compile error expected array

    Thread moved to VBA section.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: need help with error : compile error expected array

    When you declared the myarr variable, you declared it as a string rather than an array that contains strings.
    Change
     dim myarr as string
    to
     dim myarr() as string

  4. #4
    Forum Contributor
    Join Date
    03-02-2017
    Location
    uk
    MS-Off Ver
    2010
    Posts
    104

    Re: need help with error : compile error expected array

    many thanks works perfect now

  5. #5
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: need help with error : compile error expected array

    You're welcome!

+ 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 jkj115 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-27-2016, 03:01 PM
  2. [SOLVED] Compile error: expected array
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2015, 04:06 AM
  3. [SOLVED] Function Error: Compile error: Expected: list separator or )
    By goss in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-05-2014, 02:10 PM
  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. Syntax Error and Compile Error: Expected Line Number or Label...
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2011, 09:59 AM
  7. Compile Error - Expected Array
    By AccountantCost in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2009, 02:34 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