+ Reply to Thread
Results 1 to 9 of 9

Can't calculate a threshold value through a Function and a Sorting procedure of an Array

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

    Can't calculate a threshold value through a Function and a Sorting procedure of an Array

    I am trying alternative methods for calculating a minimum threshold value (0.05) using a Function, a Sort procedure, and arrays (CoursAction)

    However, I get a message that an array is expected for the Var Function.

    Does anyone have a guess what could the problem be?

    See the attachment below.


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by seigna; 05-05-2013 at 06:29 PM.

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

    Re: Can't calculate a threshold value through a Function and a Sorting procedure of an Arr

    I've had a look at the code and as far as I can see the problem is that Var isn't a VBA function, you can access it with Application.WorksheetFunction.Var.
    If posting code please use code tags, see here.

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

    Re: Can't calculate a threshold value through a Function and a Sorting procedure of an Arr

    Mmmm... but Var is just supposed to be a function I define and perform on CoursAction

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

    Re: Can't calculate a threshold value through a Function and a Sorting procedure of an Arr

    I had a different code where I named it differently and I got the same error that it was expecting an array, or that the subscript was out of range..

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

    Re: Can't calculate a threshold value through a Function and a Sorting procedure of an Arr

    What Var does is simply get the value from the array that corresponds to Int(N*A) with N=number of rows and A = 0.05

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,863

    Re: Can't calculate a threshold value through a Function and a Sorting procedure of an Arr

    Is this all in one module? I note that Sub Performance has a variable Var (double) dimensioned, then, a couple of statements later you call Var the function. I wonder if what you are seeing is a naming conflict, where VBA is having trouble resolving the double variable Var and the function Var. I would try changing the name for one of those to something unique, to avoid the potential conflict.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

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

    Re: Can't calculate a threshold value through a Function and a Sorting procedure of an Arr

    Ahhh wait, I can just rename them to Function VarB otherwise.. It shouldn't change much though. My original function is called VarHistoric (the one on the real file I am working on) and it gives the same errors..

    It is supposed to be in a module in the future. (tomorrow)

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

    Re: Can't calculate a threshold value through a Function and a Sorting procedure of an Arr

    Let me explain in more detail what I am doing there:

    As you can see, I have a file with a few column of data. I am going to perform calculations on each Column of the data (cause they correspond to stock values).
    Here, specifically, I am going to
    1. Construct a function that:
    a/ Fills an array with range values
    b/Sort the data in the array through a bubble sort procedure Sub Tri1
    c/ Extract from the array the value that corresponds to the Int(N*A) value where A is a percentage specified in the sheet, and N is the number of rows in each column.

    Now, it returns two errors: Expected Array and Subscript out of range. I have modified the code into three different things but I have never changed the fact I used that specific bubble sort procedure and that I place the values in an array. Could the problem be coming from somewhere there?

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

    Re: Can't calculate a threshold value through a Function and a Sorting procedure of an Arr

    I also addressed this issue here. http://www.excelforum.com/excel-prog...nd-arrays.html

    The code is a bit different though it is supposed to do the same thing.

+ 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