nameuser321
10-24-2012, 06:09 AM
Just creating a simple form that will allow me to select a name from a list located on another sheet. I load the combo box with the values in a named range. When I start to type the name the combo autofills based on my partial selection. When I attempt to capture the "Enter" key via the "_Keypress" sub no event is triggered. How can I capture the Enter, Tab and Backspace Keys?
Public Sub prepComboBox()
Dim arange As Range
fillComboBox Sheet1.ComboName, ThisWorkbook.Names("Headcount").RefersToRange
End Sub
Public Sub fillComboBox(aCombobox As ComboBox, arange As Range)
Dim aRow As Range
Dim index As Integer
index = 0
aCombobox.Clear
For Each aRow In arange.rows
If index <> 0 Then
aCombobox.AddItem (aRow.Cells(1, 2).value)
End If
index = index + 1
Next aRow
End Sub
This code is in the sheet with the combo box. (Triggers for every other key but 13
Private Sub ComboName_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
MsgBox "Key pressed"
End Sub
Public Sub prepComboBox()
Dim arange As Range
fillComboBox Sheet1.ComboName, ThisWorkbook.Names("Headcount").RefersToRange
End Sub
Public Sub fillComboBox(aCombobox As ComboBox, arange As Range)
Dim aRow As Range
Dim index As Integer
index = 0
aCombobox.Clear
For Each aRow In arange.rows
If index <> 0 Then
aCombobox.AddItem (aRow.Cells(1, 2).value)
End If
index = index + 1
Next aRow
End Sub
This code is in the sheet with the combo box. (Triggers for every other key but 13
Private Sub ComboName_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
MsgBox "Key pressed"
End Sub