+ Reply to Thread
Results 1 to 16 of 16

Look for each listbox item in .UsedRange

  1. #1
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Look for each listbox item in .UsedRange

    Hi, Good morning,

    So basically everything is in the title! I have a userform with a ListBox and I'm trying to refer to each particular item in the Listbox for a range but it doesn't work.

    Please Login or Register  to view this content.
    Last edited by SIMBAtheCAT; 07-18-2014 at 12:45 PM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Look for each listbox item in .UsedRange

    Please Login or Register  to view this content.
    Check the indentation of your code and it should be clear why it's not compiling.

    You have a FOR NEXT loop arounf only the IF part of your IF THEN ELSE construct.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Re: Look for each listbox item in .UsedRange

    Tried it but it is just deleting every row.

    I made this little code and it works. However, it's not as efficient as your code would be Andy Pope if it would be working.

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Look for each listbox item in .UsedRange

    My bad. You actually want to delete if match rather than if not.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Re: Look for each listbox item in .UsedRange

    No, you were right. I'm trying to keep the rows with the value in ListBox2 and hide the other rows.

    Your code seems to just delete every single rows so I made so minor modifications without success. It still hides/deletes every rows :

    Please Login or Register  to view this content.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Look for each listbox item in .UsedRange

    Hide or delete, there is a difference.
    Your original code would suggest delete.

    Can you post workbook example and detail what choices to make so we can see exactly what is happening.

  7. #7
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Re: Look for each listbox item in .UsedRange

    Sure! Here is an image of my userform with the listbox :
    Sans titre.PNG

    The red circle is the objects I want to KEEP! Those objects.text can be found in another workbook always in the first column. When the objects are not in the ListBox2 then I want to HIDE the entire row.

    Here is my code, it works BUT it takes literally 10 minutes to execute... :

    Please Login or Register  to view this content.
    Last edited by SIMBAtheCAT; 07-16-2014 at 09:45 AM.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Look for each listbox item in .UsedRange

    Yeah, not really a lot I can do with a redacted image.

  9. #9
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Re: Look for each listbox item in .UsedRange

    I'm sorry but that is the maximum I can post here... Still I appreciate the will to help.

  10. #10
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Re: Look for each listbox item in .UsedRange

    Instead of starting another thread,

    I'm trying to rename the sheets of another workbook if they don't match the objects/items in a ListBox. However, I always get 'execution error 438.

    Please Login or Register  to view this content.

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Look for each listbox item in .UsedRange

    If that code is in the userform code module then you don't need the wbthis reference. You can use the Me object instead.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Re: Look for each listbox item in .UsedRange

    No it's not in the userform code. It is in a macro and serves a error handlerpurpose :

    Please Login or Register  to view this content.

  13. #13
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Look for each listbox item in .UsedRange

    Have you not declared a object reference to you userform?

    if not, and the userform is still in memory, you could resort to using userforms collection.
    Please Login or Register  to view this content.
    Although I think you would need to determine what index value to use

  14. #14
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Re: Look for each listbox item in .UsedRange

    You are right. I just referred it manually without any loop. I'll dig more into that when I have some time off.

    Could you help me make this code more efficient because when I run it, it just stays in execute mode forever (literally)...

    Please Login or Register  to view this content.

  15. #15
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Look for each listbox item in .UsedRange

    Back to issue of needing example workbook

  16. #16
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Re: Look for each listbox item in .UsedRange

    Once again, I can't provide that. However, after a couple of changes, I made it work :

    Please Login or Register  to view this content.

+ 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. Select one item from a listbox disables another listbox
    By EagleInsight in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-22-2014, 09:53 PM
  2. [SOLVED] first item in listbox does not show in listbox
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-19-2013, 10:33 AM
  3. [SOLVED] Copy one listbox item to same index position in another listbox
    By Foreverlearning in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-19-2012, 06:05 AM
  4. Multi select Listbox Items selection based on other Listbox item selection.
    By srinivassathi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-20-2011, 05:53 AM
  5. Populate ListBox Based On Item Chosen In Another ListBox
    By davemojo82 in forum Excel General
    Replies: 1
    Last Post: 08-04-2009, 08:39 AM

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