+ Reply to Thread
Results 1 to 4 of 4

Listbox - automatically selecting an option based on a cell's value

  1. #1
    Registered User
    Join Date
    10-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    77

    Listbox - automatically selecting an option based on a cell's value

    Hi All

    I'm working on a stock management system for work.

    The workbook is attached for reference. Please see the attached screenshot image of the userform in question.

    The machines in the left listbox are from the "machinelist" worksheet, which is in the following format:

    MachineID | Machine Name | Rent Cost | GroupID

    The GroupID is picked from a group of machines which the stock is for, and comes from the "grouplist" worksheet which is as follows:

    GroupID | Group Name

    So in this edit machine userform, it pulls across the GroupID, when you select each machine from the listbox. What I need it to do is select the group that it's in automatically from the right hand group listbox.

    So in the example, you can see that "1 Cranes" is selected for E-Claw. That is correct. But if I then click on "3 Clenaflex 1 (Rec)" that is in Group 2 which is "Clenaflex & Barber Cut" so I want it to automatically highlight the 2nd option in the listbox.

    I've researched on the internet and lots of people talking about using the "ListIndex" property - however I get an error saying this is an invalid property as there is no ListIndex property for a listbox...

    Is anyone able to help at all?

    If you go into the crane.xls workbook, you'll need to click on "Load Menu" button, then machine maintenance, then it's the "edit machine" button - ignore the msgboxes that appear when it first loads - they were for diagnostic purposes.

    Thanks in advance! This is driving me mad :-(
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Smurlos; 02-09-2011 at 06:48 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Listbox - automatically selecting an option based on a cell's value

    Hello Smurlos:

    You've got some funky code there with some repop of lists etc. But I've bandaded your code in "Private Sub machinelist_Click()" by adding the following code to the very end of that specfic sub...

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Listbox - automatically selecting an option based on a cell's value

    nimrod, that works absolutely perfect, beautiful! Thank you soooo much!

    As for the funky code... yeah, I've pretty much just copied and pasted stuff from other projects I've done (you'll probably see I've posted quite a lot on here when I get into a sticky situation) but it's far from done, I'll hoover the code up a bit once I've got the basic functionality working :-)

    Thanks again for your help though. You've no idea how long I've been searching for how to do this for! Tons of stuff out there about making it select the top item as default etc etc but yeah.

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Listbox - automatically selecting an option based on a cell's value

    Hello Smurlos:
    Your very welcome , though I didn't find the root cause ... I just treated the symptom. Anyway ... thx for the Ack... cheers.

+ 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