When combobox empty nothing should happen

  • Hi all! Hope life is treating you all well!


    I have problems with my combobox (in a userform). It works properly when I select a value. It fills the concerning cell in the worksheet with that value.
    But if nothing is selected in that combobox, the cell which once was filled with a value becomes empty again.


    I just want that when no value is selected in the combobox the cell stays as it is (so the combobox doesn't do anything).


    Code
    Worksheets("Data").Activate
    ActiveCell.Offset(0, i).Range("AG1").Select
    ActiveCell.Value = UserForm1.ComboBox2.Value
    UserForm1.ComboBox2.Value = vbNullString


    sorry for my english

  • Re: When combobox empty nothing should happen


    Quote from cytop;777895
    Code
    If ComboBox2.ListIndex > -1 Then
        Worksheets("Data").Activate 
        '// remainder of code
    End If


    The ListIndex property returns the 0 based Index of the selected item. If nothing is selected then ListIndex returns -1.



    perfect I got it. Very much appreciated cytop

Participate now!

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