+ Reply to Thread
Results 1 to 8 of 8

VBA Userform Dependent Combobox

  1. #1
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    VBA Userform Dependent Combobox

    Hi al,

    I have read reams on this over various forums and nothing I try seems to work. If someone could point me in the direction of a clear and concise tutorial on this subject or help me to understand where I am going wrong, It would be sincerely appreciated.

    All I want to do is have one combobox within a userform - the options within which depend on the selection of another combobox.

    Box 1 (cboNumber)Options are (1,2,3)
    Box 2 (cboLetter)Options are (a,b,c if 1 is selected), (d,e,f if 2 is selected), (g, h, I if 3 is selected)

    Ideally I would like to draw values from a worksheet named "Worksheet1", where 1,2,3 are "A2, A3, A4", a, b, c are column "B2, B3, B4", d, e, f are column "C2, C3, C4", etc. Frankly though, I don't care how it is done, I just want to understand how to do it.

    I am very new to VBA and this issue is a small part of a larger form (most of which I have managed to accomplish using some fantastic tutorials out there). As such, please treat me like a simpleton and don't just fire some code at me on the assumption that I understand it or indeed know exactly where to place it.

    Many thanks in advance of any help!

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Userform Dependent Combobox

    Here's an example that uses the ComboBox ListIndex
    Attached Files Attached Files
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA Userform Dependent Combobox

    Thank you for the example - it does exactly what I specified and works brilliantly!

    However!

    When I go to change the number of options in each column, all works well until I try to reduce the number of options to 1 - where it returns "invalid property array Index."

    To clarify, the number of columns will vary (A, B, C, D, E, F, G, ETC) and the number of options in each colums will vary from 1 to 20 (ish),

    Unfortunately despite your attempt to explain what the code is doing to me, I still don't understans what each line is doing, so am unable to amend what I'm sure is a very simple issue.

    Again, I would appreciate any clarification (and further idiot proof explanation of the code).

    One last thing! The code will be added to an existing form, but when I have attempted to add it, it returns a mesage "ambiguous name detected UserForm_Initialize. I suspect this is because I already have the Private Sub UserForm_Initialize() command at the top of my form.

    Essentially, I need code I can simply drop into my existing code.

    I hope that makes sense!

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Userform Dependent Combobox

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  5. #5
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA Userform Dependent Combobox

    Okay, I have put together a table as an example of what I will be working with. What I would like ideally is:
    • Each of the column headers to form an option in Combobox 1 (More will be added)
    • Each of the values in the cells under the Headers to represent dependent options in Combobox 2 (these will also change, so need to comboboxes to change accordingly)
    • Also, Instead of populating the existing comboboxes in the code with the “AddItem” command, I would like to reference the relevant column on the “Data Input” sheet.

    I have included a small piece of existing code to give some idea of where I am at and how I have got there.
    What I really need now is the code to do the above, an explanation of what the code is doing would be great – and crucially, how to insert the new code into the existing code so it works!
    I hope that has clarified?


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

  6. #6
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA Userform Dependent Combobox

    Anyone?

    Any help on this would really be a life saver!

  7. #7
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA Userform Dependent Combobox

    Last bump on this one...

    Surely this is an easy resolution. The frustration is driving me nuts!

    (although I was slightly mad prior to this exercise....)

    Thanks in advance!!!!

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Userform Dependent Combobox

    There's no code in the example attached

+ 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