Consulting

Results 1 to 4 of 4

Thread: Pull information from selected row via listbox

  1. #1
    VBAX Regular
    Joined
    Mar 2023
    Posts
    28
    Location

    Pull information from selected row via listbox

    Good morning all,

    I once again could use your assistance with something.

    So I am trying to build a 'briefing generator' and I am missing a piece of the puzzle.

    I am using the following code to pull our incident codes from a column in a table, into a listbox.

    I need to be able to populate textbox fields with the information found on the row which corresponds with the selection found in the listbox.

    So if column 1 is populating the listbox, I need column 2, 3 and 4 to populate the textboxes with the row address within the listbox selection.




    Private Sub CommandButton2_Click()
    
    
    UserForm1.Show
    
    
       Dim tbl As ListObject
        Dim rng As Range
        Set tbl = ActiveSheet.ListObjects("Table6")
        Set rng = tbl.ListColumns(1).DataBodyRange
    
    
        Dim cl As Range
        For Each cl In rng
            UserForm1.ListBox1.AddItem (cl.Value)
        Next
    End Sub

    Any help you could provide on this would be extremely helpful.


    Many thanks in advance.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Attach a small workbookwith some data, the userform and your macros
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Mar 2023
    Posts
    28
    Location
    Thanks Paul_Hossler

    Please see attached
    Attached Files Attached Files
    Last edited by Aussiebear; 09-28-2023 at 04:12 AM. Reason: Corrected the Surname

  4. #4
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    Hi ecalid. Not much luck with this one. This seems to work. HTH. Dave
    Userform1 code...
    Private Sub ListBox1_Click()
    Dim tbl As ListObject
    Set tbl = Sheets("Briefing").ListObjects("Table6")
    'column D
    UserForm1.TextBox4.Text = _
              Intersect(tbl.ListRows(UserForm1.ListBox1.ListIndex + 1).Range, tbl.ListColumns(3).Range).Value
    'column G
    UserForm1.TextBox1.Text = _
              Intersect(tbl.ListRows(UserForm1.ListBox1.ListIndex + 1).Range, tbl.ListColumns(5).Range).Value
    'column E
    UserForm1.TextBox3.Text = _
              Intersect(tbl.ListRows(UserForm1.ListBox1.ListIndex + 1).Range, tbl.ListColumns(4).Range).Value
    'column I
    UserForm1.TextBox2.Text = _
              Intersect(tbl.ListRows(UserForm1.ListBox1.ListIndex + 1).Range, tbl.ListColumns(8).Range).Value
    'column J
    UserForm1.TextBox5.Text = _
              Intersect(tbl.ListRows(UserForm1.ListBox1.ListIndex + 1).Range, tbl.ListColumns(9).Range).Value
    End Sub

Posting Permissions

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