+ Reply to Thread
Results 1 to 7 of 7

Nested IF only executing first loop statement

  1. #1
    Registered User
    Join Date
    06-22-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    4

    Nested IF only executing first loop statement

    Hello, I'm new to this forum and new to VBA also. I've done a week of solid research and after gathering advice and help from all over the place I gathered the following code which worked perfectly for my original idea. I wanted to increase the rrp of an item if it had a profit margin was less than 50p until that margin was greater than 50p. Here is the code I have that works: (I'm sorry about the way I write this, I don't know how it should be indented.

    Please Login or Register  to view this content.
    Now I want to add another IF. Do I need to add a statement something like:
    Please Login or Register  to view this content.
    I've tried to adapt the current code but it just loops the first statement and completely ignores the second.

    Massive appreciation to anyone who can tell me what I need to do in order to get this working.
    Thanks in advance.
    Last edited by kewcumber; 06-22-2012 at 12:47 PM.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,576

    Re: Nested IF only executing first loop statement

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  3. #3
    Registered User
    Join Date
    06-22-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Nested IF only executing first loop statement

    Hi, sorry about not using the code tags. Newbie alert, my bad.

  4. #4
    Forum Contributor
    Join Date
    03-15-2007
    Location
    AL, USA
    MS-Off Ver
    2007
    Posts
    174

    Re: Nested IF only executing first loop statement

    A sample of your workbook would be nice so we can step through the code and see where it is getting off track.

  5. #5
    Registered User
    Join Date
    06-22-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Nested IF only executing first loop statement

    profits.xlsm

    Hi, I hope I attached this ok!

  6. #6
    Forum Contributor
    Join Date
    03-15-2007
    Location
    AL, USA
    MS-Off Ver
    2007
    Posts
    174

    Re: Nested IF only executing first loop statement

    Quote Originally Posted by kewcumber View Post
    Attachment 163662

    Hi, I hope I attached this ok!
    Ok, I found where you went wrong. When you were checking if the cell was empy, you were using .Select instead of .Value. This sent the code into infinite loop after the first "Do Unitl". I fixed that for you, and inserted the new code, so it all works on my end

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-22-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Nested IF only executing first loop statement

    oh that's fantastic, you've just solved my problem and I am grateful ten-fold! Great stuff, thanks mshare :-)

+ 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