Mouse down event to select item in combo box not working correctly
I am using an ActiveX combo box on a worksheet. I am trying to select an item with a mouse. I have found the code below and it does work. However, unless you place the mouse pointer on the very bottom of the item highlighted in blue, it will select the item above it. Is there another way to do this? or is there a way to adjust the code to make this function better?
Private Sub TempCombo_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single) If TempCombo.TopIndex > -1 Then Dim curIndex As Integer curIndex = TempCombo.TopIndex + Application.WorksheetFunction.RoundDown(y / 13.5, 0) CurValue = TempCombo.list(curIndex) End IfEnd Sub
Private Sub TempCombo_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single) With TempCombo If .ListIndex > -1 Then .ListIndex = .ListIndex + Application.WorksheetFunction.RoundDown(y / 13.5, 0) End If End WithEnd Sub
Well, I tried using your solution but I get no value whatsoever into my variable. See the code below. You essentially changed the "TopIndex" for "ListIndex". What am I missing here?
If TempCombo.ListIndex > -1 Then Dim CurIndex As Integer CurIndex = TempCombo.ListIndex + Application.WorksheetFunction.RoundDown(y / 13.5, 0) CurValue = TempCombo.list(CurIndex) End If
Open in new window