View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Peter Rooney Peter Rooney is offline
external usenet poster
 
Posts: 325
Default Nice easy Listbox queries

Matt,

Thanks for your help. However, I think you need to set up a seperate
variable to determine where in the "Target" range the selected items are to
appear. If you use I for this, the first item selected from the listbox
appears one cell above the first cell of "Target". Bob supplied the
following, incorporating an additional "positioning" variable:

Private Sub cmdOK_Click()
Dim I As Integer, J As Integer
For I = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(I) = True Then
J = J + 1
Range("Target").Cells(I, 1).Formula = ListBox1.List(I)
End If
Next I
Unload Me
End Sub

Thanks again, and have a good weekend! :-)

Pete



Private Sub UserForm_Initialize()
Range("Target").ClearContents
Dim ListCell As Range
For Each ListCell In Range("CarList")
ListBox1.AddItem ListCell.Value
Next
End Sub



"Matt" wrote:

Try the following


Private Sub UserForm_Initialize()
Range("Target").ClearContents
Dim ListCell As Range
For Each ListCell In Range("CarList")
ListBox1.AddItem ListCell.Value
Next
End Sub


Private Sub cmdOK_Click()
Dim I As Integer
For I = 1 To ListBox1.ListCount
If ListBox1.Selected(I) = True Then
Range("Target").Cells(I, 1).Formula = ListBox1.List(I)

End If
Next I
Unload Me
End Sub