PDA

View Full Version : Solved: Listbox selection



darkrider
02-21-2007, 09:13 AM
Hello to everyone,

i have 6 option buttons and when i select one them option buttons i get details to appear from my worksheet on to a list box.

what i cant do is when i click on a text in the listbox then i want it to output another part which is in my worksheet.

how can i do this

lucas
02-21-2007, 09:29 AM
Private Sub ListBox1_Click()
Range("F9").Value = ListBox1.Value
End Sub

darkrider
02-21-2007, 09:36 AM
Lucas, in listbox1 i have description of a project then when i click on that project then i would like it to show me the price in textbox1, and the price should be retrieve from my worksheet

lucas
02-21-2007, 10:04 AM
could you post a small sample of your file?
how are you populating your listbox? Can the price be in column 2 of the listbox....??? questions and more questions.

darkrider
02-21-2007, 10:13 AM
could you post a small sample of your file?
how are you populating your listbox? Can the price be in column 2 of the listbox....??? questions and more questions.

here is s sample whiic is on USERFORM1

lucas
02-21-2007, 10:31 AM
I added this listbox click code to userform1:
Private Sub ListBox1_Click()
Dim c
With ActiveSheet.Range("A:A")
Set c = .Find(ListBox1, LookIn:=xlValues)
If Not c Is Nothing Then
TextBox1 = c.Offset(0, 1).Text
End If
End With
End Sub

I dimmed c as a variant here, maybe someone will help me with the correct variant type....???

darkrider
02-21-2007, 10:38 AM
Lucas, if i want to get the mileage to appear then would i just addthis coding to it.


dim b
Set b = .Find(ListBox1, LookIn:=xlValues)

If Not b Is Nothing Then
TextBox2 = b.Offset(0, 2).Text

lucas
02-21-2007, 10:52 AM
No, it will use the same reference from the listbox. You just offset 1 instead of 2..
Private Sub ListBox1_Click()
Dim c
With ActiveSheet.Range("A:A")
Set c = .Find(ListBox1, LookIn:=xlValues)
If Not c Is Nothing Then
TextBox1 = c.Offset(0, 2).Text
TextBox2 = c.Offset(0, 1).Text
End If
End With
End Sub

darkrider
02-21-2007, 10:53 AM
In fact i got it to work.
i just added this coding and now it works great thanks.

TextBox2 = c.Offset(, 1).Text

THANKS alot LUCAS

lucas
02-21-2007, 10:58 AM
Your welcome.
Instead of a textbox I would use a label caption to return the values....looks nicer...see attached.
You can remove the text from label 5 and 6 if you want to leave them blank until you make a selection...

lucas
02-21-2007, 11:05 AM
Be sure to mark your thread solved using the thread tools at the top of the page...