+ Reply to Thread
Results 1 to 9 of 9

Can't debug this code. The Arrays are producing a Subscript out of Range error

  1. #1
    Forum Contributor
    Join Date
    04-07-2013
    Location
    France
    MS-Off Ver
    Excel 2011
    Posts
    166

    Can't debug this code. The Arrays are producing a Subscript out of Range error

    I wrote the following code and it blocks the VBA procedure at the point where I define the Arrays and nb_Actions and nb_Cours. I tried changing Valeurs Action to Variant and others but it didn't work :/
    It is a problem I have quite often.

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    04-12-2013
    Location
    Sacramento, CA
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Can't debug this code. The Arrays are producing a Subscript out of Range error

    Hello,

    Just to start, nb_Cours and nb_Actions might have to be declared as Long variable type.

    Second, I would suggest declaring your array variables in the Dims (as "Dim ValeursAction() as Double, Esperance() as Double") and then using:

    Redim Preserve ValeursAction(1 to nb_Cours)
    Redim Preserve Esperance(1 to N)

    I think that should clear it up...


    Cheers!
    Xervice

  3. #3
    Forum Contributor
    Join Date
    04-07-2013
    Location
    France
    MS-Off Ver
    Excel 2011
    Posts
    166

    Re: Can't debug this code. The Arrays are producing a Subscript out of Range error

    Ok, I'll try

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Can't debug this code. The Arrays are producing a Subscript out of Range error

    Your error portion seemed to work just fine for me. I agree that declaring them a Long would be better but integer should work. The only time I could duplicate a "subscript out of range" error was if column 2 either had no value or a value only in row one. This makes sense since you can't go (1 to 0). Below is what I did.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    04-07-2013
    Location
    France
    MS-Off Ver
    Excel 2011
    Posts
    166

    Re: Can't debug this code. The Arrays are producing a Subscript out of Range error

    I applied your suggestions CrossService and I still get that error...

  6. #6
    Forum Contributor
    Join Date
    04-07-2013
    Location
    France
    MS-Off Ver
    Excel 2011
    Posts
    166

    Re: Can't debug this code. The Arrays are producing a Subscript out of Range error

    Would you mind having a look at it here: https://docs.google.com/file/d/0Bwjh...it?usp=sharing ?
    It contains the actual project I am working with. I erased a few spreadsheets but the ones I have problems with are there

  7. #7
    Forum Contributor
    Join Date
    04-07-2013
    Location
    France
    MS-Off Ver
    Excel 2011
    Posts
    166

    Re: Can't debug this code. The Arrays are producing a Subscript out of Range error

    Could anyone at least give me a hint what is wrong in the file..? I could work around that.. now I just have no clue any longer.. I applied all previous suggestions :/

  8. #8
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Can't debug this code. The Arrays are producing a Subscript out of Range error

    One thing I DON'T see is a sheet named "Classement" in your workbook, yet you're referencing it in your code. I've added it but that doesn't seem to solve the subscript out of range error. When i step through your code, I get the error after this line
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    04-07-2013
    Location
    France
    MS-Off Ver
    Excel 2011
    Posts
    166

    Re: Can't debug this code. The Arrays are producing a Subscript out of Range error

    I just realized it too!! I actually marked Classement instead of Ponderation Sortino.. and N=4 should be placed BEFORE ReDim Preserve Esperance. It works now, except the values it returns in table ESPERANCE are zero for the first two :S

    Thanks for the help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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