+ Reply to Thread
Results 1 to 9 of 9

Code execution jumps from "end function" to the code beginning

  1. #1
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Moscow
    MS-Off Ver
    Excel 2010
    Posts
    291

    Code execution jumps from "end function" to the code beginning

    Hi all! Please help!

    The code above does the job but iterates itself like 20 times. when code gets to "End function" it jumps to the beginning and do it over and over again... have no clue what's wrong.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Code execution jumps from "end function" to the code beginning

    Why this strange loop ? For i = 5 To 5
    attach a sample file for testing
    If solved remember to mark Thread as solved

  3. #3
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Moscow
    MS-Off Ver
    Excel 2010
    Posts
    291

    Re: Code execution jumps from "end function" to the code beginning

    Thanks for replying! Sorry i cant attach (security at job place). and lop 5 to 5 is just for testing simplicity..

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Code execution jumps from "end function" to the code beginning

    What is calling the function?

  5. #5
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Moscow
    MS-Off Ver
    Excel 2010
    Posts
    291

    Re: Code execution jumps from "end function" to the code beginning

    just regular formula on the sheet - =mega_super("range").

    It's called mega_super since it combines 3 separate udfs. The point is that even 1st udf iterates itself. It's very simple for analyzing and i'm sure that in this udf the same problem. Thats why i post it here. If we find what the problem with this one, i believe the solution will work for mega_super

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Code execution jumps from "end function" to the code beginning

    Quote Originally Posted by Alexander_Golinsky View Post
    just regular formula on the sheet - =mega_super("range").
    That can't possibly work, for two important reasons:

    1. At some point in a function you must assign a value to return, which your mega_super function doesn't do:

    Please Login or Register  to view this content.
    2. There are limits to what a UDF can do and these limits exclude things like activating other sheets.

    You might be better off explaining what you're trying to do and we'll see if we can help you write something a bit neater.

  7. #7
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Moscow
    MS-Off Ver
    Excel 2010
    Posts
    291

    Re: Code execution jumps from "end function" to the code beginning

    Thanks for replying, Andrew-R!

    1. please dont worry about the value to return. This code is just for developing. Debug.Print shows the result.

    2. these udfs work with no activating sheet too. But the problem still exists.

  8. #8
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Code execution jumps from "end function" to the code beginning

    So if, say, you add a new sheet to your workbook and put the Credit_return_average formula in it still runs multiple times before returning an answer?

  9. #9
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Moscow
    MS-Off Ver
    Excel 2010
    Posts
    291

    Re: Code execution jumps from "end function" to the code beginning

    Sorry for being silly!!!

    To get this problem one should do what i did:

    1. Create udf
    2. Use it once on the sheet
    3. Drag it
    4. Edit udf and put Debug.print inside
    5. Reenter one of the dragged formulas

    As the result the udf will be recalculated as much times as it was dragged and Debug.print will print the same number of times!

    THANK YOU ALL!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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