+ Reply to Thread
Results 1 to 7 of 7

For Next Loop with IF statement inside does not loop

  1. #1
    Registered User
    Join Date
    08-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    12

    Question For Next Loop with IF statement inside does not loop

    I am working on a project (that should be simple) but I cannot get it to work. All I need it to do is to loop through a range of cells that will always start in cell D2 but will have a different ending row count every week and look for any cell that shows #N/A (from a previous vlookup formula) - then show an input box, we input the correct ID# which gets put into the cell instead, and move onto the next cell until there are no more cells. I have tried various ways of doing this and the inputbox part works (i.e. if I have #N/A in the first cell it completes what I want it to do) but it never moves on to the other cells.... please help! Here is my code at the moment (this is just an excerpt so I copied all my variable declarations even what I don't use)...
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 08-08-2013 at 09:22 PM. Reason: Added Code Tags

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: For Next Loop with IF statement inside does not loop

    Please Login or Register  to view this content.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: For Next Loop with IF statement inside does not loop

    Please Login or Register  to view this content.
    instead of If Application.IsNA(ActiveCell.Value) Then.
    The active cell is the one the cursor is in on the worksheet, not the one presently being looked at by the VBA code unless you "Select" or "Activate" which you don't usually have to do.
    Ben Van Johnson

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: For Next Loop with IF statement inside does not loop

    Untested
    Please Login or Register  to view this content.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: For Next Loop with IF statement inside does not loop

    Hello roxybethany,

    Welcome to the Forum!

    I changed "ActiveCell" to the range variable "b" in the loop. It should work now.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Registered User
    Join Date
    08-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: For Next Loop with IF statement inside does not loop

    I knew it was probably something simple --- Thank you SO much... it works perfectly now!!

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: For Next Loop with IF statement inside does not loop

    Hello roxybethany,

    YUou're welcome.

+ 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. Changing the index of a for loop inside of the loop
    By drinkmorewine in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-03-2013, 12:19 PM
  2. [SOLVED] Loop inside a loop problem!
    By questionguy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-22-2012, 12:54 PM
  3. If statement inside a loop
    By jeskit in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2011, 06:33 AM
  4. VBA For loop where number of iterations can be changed from inside loop
    By barrboy89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-11-2011, 12:18 PM
  5. Loop inside a Loop
    By jhahes in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-07-2006, 02:23 PM

Tags for this Thread

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