+ Reply to Thread
Results 1 to 7 of 7

Compile Error: Invalid ReDim

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Compile Error: Invalid ReDim

    Hi,

    I have the following code which causes an error:
    Please Login or Register  to view this content.




    However, i will now SWAP the order of the if-statements and the following code passes:
    Please Login or Register  to view this content.


    can someone explain it to me? I have also submitte my actual file incase some one wanted to see it.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Compile Error: Invalid ReDim

    From your test array fails module, type Dim junk_array() As Variant in the beginning of the module then try again.

    And, I am not sure if you can assign a value to a range. ' junk_array = ws.Range("A1:B" & last_row_1).Value
    Last edited by JieJenn; 08-02-2013 at 11:37 AM.

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

    Re: Compile Error: Invalid ReDim

    Try declaring junk_array, as well as all your other variables eg ws, last_row1 etc.
    If posting code please use code tags, see here.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,427

    Re: Compile Error: Invalid ReDim

    It's the position of the redim statement after the first instance of the variable. the compiler makes an assumption based on first encounter and then subsequent syntax breaks that assumption.

    If you declare junk_array at the top the compile problem goes away

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Compile Error: Invalid ReDim

    thanks for responding.

    Andy, i tried what you suggested and it worked great! thanks.

    I dont know why but i have had trouble with this kind of thing in the past and i think its because i dont know how to declare arrays properly.

    for example

    Dim Junk1_array as variant


    is not the same as

    Dim Junk1_array() as variant



    do any of you know a link which explains this difference and others for declaring arrays and how to do it.

    thanks!

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,427

  7. #7
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Compile Error: Invalid ReDim

    thanks for the info

+ 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: Invalid Outside Procedure
    By packet25 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-13-2013, 07:02 AM
  2. Compile error: Invalid qualifier
    By naistinali in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-06-2013, 01:43 PM
  3. Compile Error: Invalid outside procedure
    By smylod in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-27-2009, 01:56 PM
  4. Compile Error: Invalid use of object
    By Barb Reinhardt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2006, 03:05 PM
  5. Replies: 1
    Last Post: 02-17-2006, 12:10 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