ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ListBox "picking the same item repeatedly" (https://www.excelbanter.com/excel-programming/308330-listbox-picking-same-item-repeatedly.html)

TK

ListBox "picking the same item repeatedly"
 
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


Tom Ogilvy

ListBox "picking the same item repeatedly"
 
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

--
Regards,
Tom Ogilvy



"TK" wrote in message
...
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




TK

ListBox "picking the same item repeatedly"
 

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



"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy



"TK" wrote in message
...
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





Tom Ogilvy

ListBox "picking the same item repeatedly"
 
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

--
Regards,
Tom Ogilvy


"TK" wrote in message
...

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



"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy



"TK" wrote in message
...
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








All times are GMT +1. The time now is 10:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com