+ Reply to Thread
Results 1 to 4 of 4

Logic Error - Code Is Looping Back

  1. #1
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Logic Error - Code Is Looping Back

    Hi all,

    Using Excel 2013.

    Code below:
    • Prompt user to select cell on a worksheet.
    • If worksheet does not contain data, ask user if wants to try another worksheet, if so try again, else exit.
    • If worksheet does contain data, the true used range is output perfectly.

    I'm testing beginning on a worksheet on a worksheet with no data.
    I am prompted to select a cell on another worksheet which I do

    The results output correctly as the name of the worksheet and the address of the cell with data
    But then the name of the worksheet is output again and I receive an object defined error here:
    Please Login or Register  to view this content.
    Any thoughts on why this apparent "Loop Back"

    thx
    w

    Please Login or Register  to view this content.
    Kind regards,
    w

    http://dataprose.org

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Logic Error - Code Is Looping Back

    Please Login or Register  to view this content.
    With the recursive call, a new instance of the procedure starts, and the current instance suspends (but doesn't end). So when the 2nd instance is complete, the original instance continues and then errors.

    Put an Exit Sub after the Recursive call.

    Alternatively, put a code Label at the top of the procedure and use a GoTo statement.

    Please Login or Register  to view this content.
    On another note: Don't you find using separate procedure calls just to display messages\prompts more complicated than having the code within the calling procedure?
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Re: Logic Error - Code Is Looping Back

    Thanks AlphaFrog,

    Don't you find using separate procedure calls just to display messages\prompts more complicated than having the code within the calling procedure?
    Definitely.

    For me, it's a discipline. I need to practice to force myself to break down as much as I can into Functions() and Subs().
    I'll look at the "Exit Sub" later tonight.

    thx
    w
    Last edited by goss; 10-06-2014 at 07:21 AM. Reason: typo

  4. #4
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Re: Logic Error - Code Is Looping Back

    Thanks AlphaFrog,

    The Exit Sub did the job perfectly!

    thx
    w

+ 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] Help on looping program logic
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-15-2013, 12:36 PM
  2. [SOLVED] logic stmt. use in a new workbook w/o refering back to original
    By billybob in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 11:05 AM
  3. logic stmt. use in a new workbook w/o refering back to original
    By billybob in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  4. logic stmt. use in a new workbook w/o refering back to original
    By billybob in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  5. Code logic error
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2005, 11:05 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