Consulting

Results 1 to 7 of 7

Thread: Clearing entry from VBA Combo Box

  1. #1

    Clearing entry from VBA Combo Box

    Hi my combo box has two choices, YES and NO. If the user selects Yes and Select the box hides but the next time it opens it shows Yes again is there any way to make the box set to Blank? the code I'm using is below.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("ag63").Value = 1 Then
    cboGSTINPUT.Show
    Exit Sub
    End If
    If Range("ag63").Value = 0 Then
    cboGSTINPUT.Hide
    Exit Sub
    End If
    End Sub

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Why use a combo box for two choices. CheckBoxes, or ToggleButtons are designed for binary (yes/no) inputs.

    To clear a combobox
    [VBA]cboGSTINPUT.ListIndex = -1[/VBA]

  3. #3
    The combo box asks a question to reinforce that the user really wants proceed with his entry.

    Where should I put the code that you sent?

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Either before the .Show or after the .Hide

  5. #5
    I"m still confused as to how to apply this

    Any help would be appreciated.

  6. #6
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Put that line into your routine.
    Putting it either before the .Show line or after the .Hide line will give the user the same experience. The only difference is that after the .Hide line will make the user's previous choice unavaliable for being polled by other routines, that may run while the combobox is hidden.

    Considering that it, I would think that before the .Show line would be the best place to put that code.

  7. #7
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location
    [vba]
    Private Sub Worksheet_Activate()
    With Me.ComboBox1
    .ListIndex = -1
    .ListFillRange = "b1:b2" 'your list wherever it is with 'Yes and No' in it.
    End With
    End Sub
    Private Sub Worksheet_Change(ByVal Target As Range)
    Set Target = Range("a1") 'your range here.
    If Target.Value = 1 Then
    Me.ComboBox1.Visible = True
    ElseIf Target.Value = 0 Then
    Me.ComboBox1.Visible = False
    End If
    End Sub

    [/vba]
    Last edited by david000; 09-15-2008 at 11:33 PM.

Posting Permissions

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