none
Userform Combo Box that displays same initial value RRS feed

  • Question

  • Dear Friends

    I have a userform in which I am using a combo box  that takes values from a list on a spreadsheet. The problem is that when I close the form and move to other sections of the program and later return it remembers my former selection. I would like it to display the same initial value and not remember my previous choice.

    Below is the code I have tried using:

    Private Sub UserFormHome_Activate()
            Set ComboBoxShona.Value = Worksheets("Data").Range("B2").Value
    End Sub
    
    
    Private Sub ComboBoxShona_Change()
         Select Case ComboBoxShona.Value
            Case "Shona"
            Case "English"
                Unload Me
                UserFormHomeEnglish.Show
                
        End Select
    End Sub
    

    where "B2" contains the value "Shona", which is what I want the combo box to display first at all times.

    Your help is greatly appreciated.

    LWS

    Thursday, October 27, 2016 8:24 PM

All replies


  • Edit...
    the path diverged and I took the one less traveled

    Friday, October 28, 2016 12:14 AM
  • Hi Leslie Wellington,

    I stored a list of values on excel Sheet. like below.

    Then I create 2 userforms. on first userform I create combobox and button.

    I write the code on Form_initialize event

    Private Sub UserForm_Initialize()
    Dim cLoc As Range
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")
    
    For Each cLoc In ws.Range("combodata")
    With Me.ComboBox1
        .AddItem cLoc.Value
      End With
    
    Next cLoc
    
    ComboBox1.SelText = "Shona"
    End Sub
    

    when I click on button second user form will open. from there I again return to first user form and Shona will be selected by default. when I load the first userform then also shona will be displayed.

    like below.

    just I select the text shona on initialize event of form.

    ComboBox1.SelText = "Shona"

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 28, 2016 2:52 AM
    Moderator