Consulting

Results 1 to 7 of 7

Thread: UserForm:ComboBox1 select show and change data ListBox and ComboBox2

  1. #1

    Please....Help me with UserForm:ComboBox1 select show data on ListBox and ComboBox2

    Please someone help me with this userform
    thanks
    Last edited by sengsara; 02-28-2009 at 12:31 AM. Reason: upload sample worksheet

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Put this in the userform's code module
    [VBA]Private Sub ComboBox1_Change()
    Call FillBox(ComboBox1.ListIndex + 1)
    End Sub

    Private Sub OptionButton1_Click()
    Call FillBox(1)
    End Sub

    Private Sub OptionButton2_Click()
    Call FillBox(2)
    End Sub

    Private Sub OptionButton3_Click()
    Call FillBox(3)
    End Sub

    Sub FillBox(index As Long)
    Dim currentSelection As Long
    Dim fillList As Variant
    If index < 1 Or 3 < index Then Exit Sub
    With Range("g2").Cells(1, index)
    fillList = Application.Transpose(Range(.Cells(1, 1), .End(xlDown)).Value)
    End With
    With Me.ListBox1
    currentSelection = IIf(.ListIndex < UBound(fillList), .ListIndex, -1)
    .List = fillList
    .ListIndex = currentSelection
    End With
    With Me.ComboBox2
    .List = fillList
    .ListIndex = currentSelection
    End With
    Me.Controls("OptionButton" & index).Value = True
    ComboBox1.ListIndex = index - 1
    End Sub

    Private Sub ComboBox2_Change()
    ListBox1.ListIndex = ComboBox2.ListIndex
    End Sub

    Private Sub ListBox1_Change()
    ComboBox2.ListIndex = ListBox1.ListIndex
    End Sub

    Private Sub UserForm_Initialize()
    With Me.ComboBox1
    .AddItem OptionButton1.Caption
    .AddItem OptionButton2.Caption
    .AddItem OptionButton2.Caption
    End With
    End Sub[/VBA]

  3. #3
    Hi Mike thanks for replay
    I put the code into userform but when i run it
    is run time error"70" permission denied
    what wrong Mike

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    What line gets the error?

  5. #5
    error line...


    ----> UserForm1.Show

    but am using Excel2007

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    F8 through the code to see that problem is when it tries to add an item to combobox1 in the userform's Initialize event. This is because Mike used the RowSource property in the userform's Comobox1. Not sure why Mike used it and AddItem. Remove the A25:A27 in it to fix it. If you need that added, you will need to use the List property to fill it or AddItem for each cell initially.

    Press F4 in the Userform if you do not have the Properties window displayed so that you can edit the property.

  7. #7
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Quote Originally Posted by Kenneth Hobs
    ...Mike used the RowSource property in the userform's Comobox1. .....
    Thats odd, RowSource isn't supported on my Mac, so I didn't use it. When I open the file, I don't see RowSource in my code. Possibly the OP file has a combobox with RowSource set from the propreties window that doesn't show on my Excel2004. In which case, it should be set to null.

    Sengara, you have this functionality in the sheet you put as an example. Why put it in a userform? The sheet you have will be easier to maintain than a UF.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •