-
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
-
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]
-
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?
-
Either before the .Show or after the .Hide
-
I"m still confused as to how to apply this
Any help would be appreciated.
-
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.
-
[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
-
Forum Rules