+ Reply to Thread
Results 1 to 8 of 8

Loop/Step backwards through ListBox until criteria is met?

  1. #1
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Loop/Step backwards through ListBox until criteria is met?

    Hi all,

    I have a tricky question (well, maybe not):

    How can I "step back"/loop backwards through my listBox until my criteria is met, then trigger the code below?:

    This is the criteria: ListBox.List (LLi, 1) <> "Del"

    What I am trying to do: Update the last ListBox1.List(LLi, 8) item field that does not have the text "Del" in the ListBox.List (LLi, 1) field.

    My Code:
    Please Login or Register  to view this content.
    Thank you!
    Last edited by onmyway; 06-02-2015 at 09:53 AM.
    Sharing knowledge, can be likened to taking another person's hand, and pulling them up to a higher level -- onmyway

    If I was helpful, please remember to click on * Add Reputation below

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Loop/Step backwards through ListBox until criteria is met?

    It's easy to step backwards.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Loop/Step backwards through ListBox until criteria is met?

    Hi Norie,

    Thanks for the response. It makes sense.

    However, I am getting an Object Required error on the line: For LLi = ListBox.listCount - 1 To 0 Step -1

    Here is my code:

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Loop/Step backwards through ListBox until criteria is met?

    I assumed from your post that your listbox was actually called ListBox, for example ListBox.List (LLi, 1).

  5. #5
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Loop/Step backwards through ListBox until criteria is met?

    *blush*

    Jap, called ListBox1..... There is no emoticon to express my embarrassment.

    One more question: How can I stop the Step once the criteria was met and the code ran?

  6. #6
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Loop/Step backwards through ListBox until criteria is met?

    In other words, I only want the code to run once when the criteria was met.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Loop/Step backwards through ListBox until criteria is met?

    Use Exit For to, well, exit the For.

  8. #8
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Re: Loop/Step backwards through ListBox until criteria is met?

    Well, thank you For you 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. [SOLVED] Filtering a ListBox with a TextBox - step by step if possible
    By lol900 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2014, 06:50 PM
  2. [SOLVED] For loop backwards
    By grkchakri in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2013, 07:49 AM
  3. [SOLVED] Set Loop Backwards
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-29-2013, 02:21 PM
  4. [SOLVED] Loop through named range backwards and populate based on criteria from adjacent cells
    By CDEG in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2013, 05:56 AM
  5. [SOLVED] For step loop, need step size to change based on reference cell in row
    By Telperion in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-22-2013, 03:41 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