+ Reply to Thread
Results 1 to 6 of 6

Subscript out of range error in a Sub procedure with ranges and arrays

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

    Subscript out of range error in a Sub procedure with ranges and arrays

    I have written the following VBA Code, and at one point I place values from a Range (CoursAction) into an array(ValeursAction). Later on I use the values in the array to obtain a threshold value (Var). However, I get a "Subscript out of range" error though I think I have defined everything.

    Or is it ValeursAction() As Variant that is incorrect? It is supposed to be an array... Or should I Re-dimension it? I am sorting it with Call Tri1(ValeursAction).

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by seigna; 05-05-2013 at 02:03 PM. Reason: Clearer explanation

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Subscript out of range error in a Sub procedure with ranges and arrays

    Hi

    Your sub must be taking forever to run.

    I made a change as below
    Please Login or Register  to view this content.
    to cut down the size of the range being actioned.

    I found the error on the line
    Please Login or Register  to view this content.
    In your example file there is no sheet Performance des fonds. Is that a problem with the example file, or is that the real error?

    rylo

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

    Re: Subscript out of range error in a Sub procedure with ranges and arrays

    no, that's just me who didn't change it. It's supposed to be the first sheet. Performance. In the original file there's no such mistake and still it doesn't read well..

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Subscript out of range error in a Sub procedure with ranges and arrays

    Hi

    OK, changed that and found it is failing on the next line
    Please Login or Register  to view this content.
    Looking at the values in the variables:
    NB: 14
    alpha: 0.05
    When you multiply those, you get 0.7 and the INT then gives you 0. As this isn't a valid index for the array valeursaction (lbound is 1) then you are getting the error.

    Does this help in knowing what to do to correct your code?

    rylo

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

    Re: Subscript out of range error in a Sub procedure with ranges and arrays

    Isn't Int supposed to round UP? to 1?

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Subscript out of range error in a Sub procedure with ranges and arrays

    Hi

    No, INT just takes the integer component of the number (for positive numbers). From the help file
    Rounds a number down to the nearest integer
    rylo
    Last edited by rylo; 05-06-2013 at 08:56 PM.

+ 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