PDA

View Full Version : [SOLVED:] Another listbox selection problem



gibbo1715
08-31-2005, 02:53 AM
I use a userform to display the first entry about an item in a list , i then use the code below to show the history of that item in the userform listbox based on the user input (Exhibit and Cells).


frmList.ListBox1.Clear
Set oLB = frmList.ListBox1
With ThisWorkbook.Sheets("Exhibits")
If Range("A3").value = "" Then
LastRow = Range("3")
Else
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
End If
For i = 3 To LastRow
If Cells(i, "A").value = Exhibit And Cells(i, "C").value = Item Then
oLB.AddItem Cells(i, "A")
oLB.List(oLB.ListCount - 1, 1) = Cells(i, "B")
oLB.List(oLB.ListCount - 1, 2) = Cells(i, "C")
oLB.List(oLB.ListCount - 1, 3) = Cells(i, "D")
oLB.List(oLB.ListCount - 1, 4) = i
End If
Next i
End With

What i would like to be able to do is instead of requesting the user input I would like it to display the history of the item if they have selected it from the listbox items.

I have used a variation of the code below (kindly supplied by Killian) to identify if a listbox item is selected and add the contents to a spreadsheet but wondered if i could achieve the above?




For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
MsgBox ListBox1.List(i, 0) & " is selected"
End If
Next


Hope that made sense and thanks for your help

Gibbo

gibbo1715
08-31-2005, 05:20 AM
This seems to work for me if only one item is selected 9As should be the case)


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

Thanks for looking

Gibbo