Consulting

Results 1 to 11 of 11

Thread: Solved: Listbox selection

  1. #1

    Solved: Listbox selection

    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

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    [vba]Private Sub ListBox1_Click()
    Range("F9").Value = ListBox1.Value
    End Sub
    [/vba]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    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

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Quote Originally Posted by lucas
    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

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I added this listbox click code to userform1:
    [vba]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[/vba]

    I dimmed c as a variant here, maybe someone will help me with the correct variant type....???
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Lucas, if i want to get the mileage to appear then would i just addthis coding to it.

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

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

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    No, it will use the same reference from the listbox. You just offset 1 instead of 2..
    [VBA]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[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    In fact i got it to work.
    i just added this coding and now it works great thanks.

    [VBA]TextBox2 = c.Offset(, 1).Text[/VBA]

    THANKS alot LUCAS

  10. #10
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  11. #11
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Be sure to mark your thread solved using the thread tools at the top of the page...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •