loop through Combobox

A

akyhne

Whenever I goto the end of my Combobox (last listnumber) with my Keys, I want the control to goto listindex -1. In another way when I tab into a ComboBox and use my keys to go through the values, I want the control to start all over whenever I reach the last value

Another control I could use is whenever I use my mouse to go through the values, I want the top value to change with the (with mouse) highlighted value
 
B

Bob Phillips

Add this code to your userform

Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
With Me.ComboBox1
Select Case KeyCode
Case 40 ' : 'down arrow
If .ListIndex = .ListCount - 1 Then
.ListIndex = -1
End If
End Select
End With
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

akyhne said:
Whenever I goto the end of my Combobox (last listnumber) with my Keys, I
want the control to goto listindex -1. In another way when I tab into a
ComboBox and use my keys to go through the values, I want the control to
start all over whenever I reach the last value.
Another control I could use is whenever I use my mouse to go through the
values, I want the top value to change with the (with mouse) highlighted
value
 
B

Bob Phillips

Only by putting it in a function and call the function from each passing the
combobox as an argument.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

akyhne said:
Works great!
What if I want to run this code on 13 Comboboxes. Can this be automated so
I only write the code once
 
Top