+ Reply to Thread
Results 1 to 6 of 6

If / Then statement is creating an infinite loop when filling in a cell

  1. #1
    Registered User
    Join Date
    12-21-2011
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2007
    Posts
    3

    If / Then statement is creating an infinite loop when filling in a cell

    Hey everyone,

    I'm working on a spreadsheet that uses dropdowns (Yes/No) in certain cells that turn other cells gray or enter text into specific cells.

    For most of the cells, I just want the color to change. This works without a problem:

    Please Login or Register  to view this content.
    However, if I try to insert text into another cell, I get a long run-time error that says "Method 'Color' of object 'Interior' failed.

    Please Login or Register  to view this content.
    When I stepped through the code in debug mode it worked fine with just the colors, i.e. it would get to End Sub and stop. However, as soon as it gets to the part where it should insert the text, it skips back to the top of the Private Sub and loops through infinitely.

    Any suggestions are appreciated. Thanks!

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: If / Then statement is creating an infinite loop when filling in a cell

    I think you need to post all your code.

  3. #3
    Registered User
    Join Date
    12-21-2011
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: If / Then statement is creating an infinite loop when filling in a cell

    Thanks for your reply.

    This is the complete code:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: If / Then statement is creating an infinite loop when filling in a cell

    If you change the contents of a cell, you will retrigger the Change event.

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    12-21-2011
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: If / Then statement is creating an infinite loop when filling in a cell

    Hey,

    Thanks for the response. Sorry for the late reply - got sidetracked on another project.

    I'm new to programming, so I'm not sure how to go about this issue. Is there a way to change the contents of a cell without triggering the Change event?

    Thanks

  6. #6
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: If / Then statement is creating an infinite loop when filling in a cell

    Shg has supplied the way to do this.

    Please Login or Register  to view this content.

+ 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