ListBox "picking the same item repeatedly"

G

Guest

Hi:

On a UserForm I have the following:

Private Sub ListBox1_Click()
ActiveCell.Value = UserForm1.ListBox1.Value
ActiveCell.Offset(1, 0).Activate

End Sub


And on a Worksheet the following:

Private Sub CommandButton3_Click()
UserForm1.ListBox1.RowSource = "Sheet1!A1:A5"
UserForm1.Show
End Sub


This works ok within its’ limitations but I would like to be able to select
the same item multiple times by clicking it, without moving the cellpointer
to (and by so doing, picking) the next item in the list..

Any suggestions or examples will be greatly appreciated.
Thanks

TK
 
T

Tom Ogilvy

Private Sub ListBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ListBox1.ListIndex = -1
End Sub
 
G

Guest

Thanks again Tom Works great


I also tried to trap the enter key with some VB code but no luck.

Private Sub ListBox1_KeyPress(KeyAscii As Integer)
ListBox1.SetFocus
If KeyAscii = vbKeyReturn Then ActiveCell.Value = UserForm1.ListBox1.Value
End Sub

Would you suggest a fix?

Thanks
 
T

Tom Ogilvy

From help on Keypress:
A KeyPress event does not occur under the following conditions:

· Pressing TAB.
· Pressing ENTER.
· Pressing an arrow key.
· When a keystroke causes the focus to move from one control to another.

Not sure what you are trying to accomplish, but
Try keyup
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top