Get/Determine Selected Item In ComboBox

  • Re: Selected Item From The Combo Box


    Quote from alia

    hi,
    is there any way to get the value for the selected item from the combo box in vba code?


    thanks =)


    alia, could you be more specific.


    where is the combo box, on a spreadsheet or user form?


    what do you want to do with the value?


    if you can elaborate forum users may be able to better answer your question


    this code assumes your combo box is in a user form, and takes the value selected from the combobox and writes it to Cell A1 of the active spreadsheet.


    Hope it helps


    Code
    Private Sub ComboBox1_Change()
        Range("A1") = ComboBox1.Value
    End Sub
  • Re: Get/Determine Selected Item In ComboBox


    hi,
    Sorry if my explanation was unclear. The combobox is on a userform.
    Thing is, with the value of the combobox, will open a worksheet.
    I guess what i should have asked was..


    1) Is there a way to not allow the user to key in any values in the combobox?
    2) Is there a way to check if the user have made a selection in the combobox? Coz a selection MUST be made..



    thanks again =)

  • Re: Get/Determine Selected Item In ComboBox


    Check for a valid selection like this.

    Code
    Private Sub CommandButton1_Click()
        If cboTech.ListIndex < 0 Then
           MsgBox "You must make a selection"
           cboTech.SetFocus
           Exit Sub
        End If
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!