+ Reply to Thread
Results 1 to 9 of 9

Find next iteration in loop!

  1. #1
    Registered User
    Join Date
    04-24-2019
    Location
    Bogota,Colombia
    MS-Off Ver
    2013
    Posts
    42

    Find next iteration in loop!

    Hi guys, I've been trying to make a loop activate the cells (one at a time) that fulfils a condition but it gets stuck only on the first cell that fulfils the condition and if you run the macro again, it stays there!

    Thank you!
    Attached Files Attached Files
    Last edited by realbestpete; 05-25-2022 at 06:12 PM.

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Find next iteration in loop!

    Should work like this:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Registered User
    Join Date
    04-24-2019
    Location
    Bogota,Colombia
    MS-Off Ver
    2013
    Posts
    42

    Re: Find next iteration in loop!

    Hi and thank you very much for your reply. There are a couple of things I have to mention;

    On the sample file I uploaded here, to play the macro from a cell outside the named range works well. However, in the actual spreadsheet I'm going to use at work, it presents two problems;

    1. When I play the macro from a cell that is outside the named range (which I require in the actual spreadsheet), it starts finding ocurrences from the second ocurrence, not from the first one.
    2. When I play the macro from a different sheet (which I also require in the actual spreadsheet), it presents an error; Method 'Intersect' of object '_Application' failed. This also happens with the sample file I uploaded here.
    3. It would help me a lot to have the option to not only start finding ocurrences from top to bottom but also from bottom to top.

    I would appreciate it if you could give me a hand on that!
    Attached Files Attached Files
    Last edited by realbestpete; 05-24-2022 at 02:47 PM.

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Find next iteration in loop!

    Hi there,

    You can activate the sheet before searching the cells:

    Please Login or Register  to view this content.
    WBD
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    04-24-2019
    Location
    Bogota,Colombia
    MS-Off Ver
    2013
    Posts
    42

    Re: Find next iteration in loop!

    Hi, thanks for the reply. That solved the problem playing the macro from a different sheet. However, I still get the second ocurrence of the "OK" Status rather than the first one, when the active cell is not within the "Status" named range. I have uploaded another sample to show this situation!

    Thank you!
    Attached Files Attached Files
    Last edited by realbestpete; 05-24-2022 at 04:33 PM.

  6. #6
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Find next iteration in loop!

    OK. That only happens if the first cell in the range is "OK". You could change the range to include the header or adjust the code like this:

    Please Login or Register  to view this content.
    WBD

  7. #7
    Registered User
    Join Date
    04-24-2019
    Location
    Bogota,Colombia
    MS-Off Ver
    2013
    Posts
    42

    Re: Find next iteration in loop!

    Thank you very much! It worked!

    It's just that I thought that once the 'find "OK"' macro was working, I could easily replicate that to make it do the same for "Current" values and to add two conditions, since I had achieved that with a For Each... Next Statement (except of course that it didn't show me the next occurrence and that is why I asked for help here) so I'm going to ask you to please help me on that too:

    1. Find the values only if the corresponding "Status1" column has the value of "FALSE".
    2. Find not only "OK" values but also "Current".
    3. If the value found is "OK", activate the corresponding cell on the "Status1" column and if the value found is "Current", then activate that cell, which is in the "Status" column.

    I have been trying all these hours but couldn't do it! Thank you so much for your help and I hope with this, I can finally close this thread!
    Attached Files Attached Files

  8. #8
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Find next iteration in loop!

    If you're original question is answered, please create a new thread for a new question - that way you'll attract more viewers to your post.

    WBD

  9. #9
    Registered User
    Join Date
    04-24-2019
    Location
    Bogota,Colombia
    MS-Off Ver
    2013
    Posts
    42

    Re: Find next iteration in loop!

    Ok WBD, thank you for your kind help!

+ 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. For-loop stuck on last iteration value
    By CheckpointCharlie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-05-2020, 07:26 AM
  2. Run an entire loop instead of iteration by iteration when stepping into code?
    By Norcal1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-24-2019, 04:20 PM
  3. For Loop Iteration ?
    By distantkitty in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-09-2017, 03:14 PM
  4. [SOLVED] My loop is missing last iteration
    By elmnas in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-22-2016, 06:46 PM
  5. [SOLVED] Go to next loop iteration if current loop has error
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-03-2016, 09:54 PM
  6. VBA - How to continue inner loop while going to next iteration of outer loop?
    By alviniac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2015, 11:21 PM
  7. [SOLVED] Last Iteration of Loop?
    By saintplay in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2015, 08:19 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