+ Reply to Thread
Results 1 to 4 of 4

While loop help for a newbie!

  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2007/2010
    Posts
    28

    Question While loop help for a newbie!

    Hi,

    Trying to cause certain pictures to be pasted on my spreadsheet when the user inputs the criterias.

    My intention with the code below check while Cell A20 contains "Beachlands A" then check B20 if > 0 or = 0 then do specific statements. Theres is no error at the moment thanks to 6stringjazzar from excel forum, however, once i execute the macro and cell A20 contains "Beachlands A" it seems like it's checking till judgment day or so.. the spreadsheet also becomes unresponsive and i would have to terminate excel all together.

    Please Login or Register  to view this content.
    Have I structured the while loop to check infinite times?

    I would appreciate some insight on this

    Thanks

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: While loop help for a newbie!

    Unless I am missing something I don't understand why you need a loop. It appears to me that you are simply checking the value in two cells. Something like this should work, provided the other parts worked they way you wanted:

    Please Login or Register  to view this content.
    Note: You may want to specify the worksheet that way you don't run into an activeworksheet problem
    Last edited by stnkynts; 11-15-2012 at 05:59 PM.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,167

    Re: While loop help for a newbie!

    I agree with stnkynts.

    Just for the sake of education, yes, you have structured an infinite loop. You are testing for a condition each time through the loop, yet you do nothing inside the loop that could change that condition. So the loop runs either zero times or never stops.

    By the way, hitting ALT-F4 is the nuclear option. Most (but not all) of the time, if you have a runaway macro, you can interrupt it by hitting BREAK (maybe ALT-BREAK). My machines all have a PAUSE/BREAK key. This will interrupt the code and put you in debug mode.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    10-10-2012
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2007/2010
    Posts
    28

    Re: While loop help for a newbie!

    I kinda guessed so.. Thanks for the confirmation 6string! and thanks for the solution stnkynts!
    Great forum!

+ 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