• ComboBox in a Userform

    Author
    Topic
    #460155

    Hello,

    What I’m trying to do is utilize a ComboBox in a userform to populate a certain cell.

    Here is the code I have for the ComboBox:

    Private Sub ComboBox1_Enter()

    ComboBox1.List() = Range(“R1:R49”).Value

    End Sub

    As you can see, I’m populating the data in the combobox from data in column R. I can select what I desire, so I’m good so far. What I need to happen is for whatever selection is made to be populated in another cell (for example purposes, let’s use A1). After it’s populated, I need the userform to go away. I can figure that out…I just haven’t got that far yet.

    Thanks for any advice. It is much appreciated.

    I’m using Excel 2007

    Viewing 0 reply threads
    Author
    Replies
    • #1162551

      You can set the RowSource property of the combo box to R1:R49 in the Visual Basic Editor instead of in code, and you can set the ControlSource property to the address of the cell to which you want to link the value of the combo box, e.g. A1 – again, no code necessary.

      • #1162575

        You can set the RowSource property of the combo box to R1:R49 in the Visual Basic Editor instead of in code, and you can set the ControlSource property to the address of the cell to which you want to link the value of the combo box, e.g. A1 – again, no code necessary.

        Hey, thanks for the pointer on that. I got it to work, but it only populates the cell when I click the X to close it.

        Now that I’m not using code, I’m not sure how to make the userform go away.

        • #1162583

          If selecting an item in the combo box made the userform go away, the user wouldn’t be able to correct mistakes. So I’d place a command button cmdClose next to the combo box with the following code:

          Code:
          Private Sub cmdClose_Click()
            Unload Me
          End Sub
          • #1162584

            If selecting an item in the combo box made the userform go away, the user wouldn’t be able to correct mistakes. So I’d place a command button cmdClose next to the combo box with the following code:

            Code:
            Private Sub cmdClose_Click()
              Unload Me
            End Sub

            Very nice.

            That did it. Thanks for the tips and the help.

    Viewing 0 reply threads
    Reply To: ComboBox in a Userform

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: