ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   List boxes (https://www.excelbanter.com/excel-programming/305457-list-boxes.html)

Joe Powers

List boxes
 
Hi,
I have an option button on a worksheet that activates a
list box when the user clicks it. I ask the user to select
up to 15 items in the list box. I would like to take the
user's selections from the list box and store them in a
column on another worksheet in the workbook. Does anyone
have any idea/code that I could use to accomplish this
task?

Simon Livings

List boxes
 
There are a few methods for doing this, but the following code is
probably the simplest (not tested):

Sub PrintSelection()
Dim i As Integer, iCount As Integer

For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
iCount = iCount + 1
Cells(iCount, 1) = ListBox1.List(i)
End If
Next i

End Sub


HTH
Simon Livings

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Joe Powers

List boxes
 
Simon,
I have added the code you sent me to the Private Sub
ListBox_Hosp_Click() portion of my list box, but when I make my
selections, the selections do not appear anywhere on my worksheet?
Here is what I have:
'Private Sub ListBox_Hosp_Click()
Sub PrintSelection()
Dim i As Integer, iCount As Integer

For i = 0 To ListBox_Hosp.ListCount - 1
If ListBox_Hosp.Selected(i) Then
iCount = iCount + 1
Cells(iCount, 1) = ListBox_Hosp.list(i)
End If
Next i

End Sub
'End Sub

Any thoughts?
Joe



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Norman Jones

List boxes
 
Hi Joe,

I tried Simon's code in the ListBox DblClick event , and it functioned, as
intended, entering the selected values in cells A1 downwards.

---
Regards,
Norman


"Joe Powers" wrote in message
...
Simon,
I have added the code you sent me to the Private Sub
ListBox_Hosp_Click() portion of my list box, but when I make my
selections, the selections do not appear anywhere on my worksheet?
Here is what I have:
'Private Sub ListBox_Hosp_Click()
Sub PrintSelection()
Dim i As Integer, iCount As Integer

For i = 0 To ListBox_Hosp.ListCount - 1
If ListBox_Hosp.Selected(i) Then
iCount = iCount + 1
Cells(iCount, 1) = ListBox_Hosp.list(i)
End If
Next i

End Sub
'End Sub

Any thoughts?
Joe



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




Joe Powers

List boxes
 
Norman,
You are correct, I changed the event on my list box to DblClick and the
code Simon sent does work. One more question. I only want the user to
select up to 15 data points from my list box, is there a way to modify
Simon's code to accomplish this?
TIA
Joe



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 11:00 PM.

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