Consulting

Results 1 to 4 of 4

Thread: Solved: Listbox, should be simple!

  1. #1
    VBAX Newbie
    Joined
    Oct 2010
    Posts
    2
    Location

    Solved: Listbox, should be simple!

    Any help would be welcome.
    I have a userform with one listbox populated with a named range (Names).
    also on the form are 2 textboxes for the user to input 2 numbers.
    When the user clicks OK button the selected listbox name should be looked up against the named range on the worksheet and the 2 textbox values written to the next 2 adjacent columns.
    Thanks Pete

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [vba]Private Sub ListBox1_Click()
    Dim r As Range
    Dim i As Long
    i = ListBox1.ListIndex + 1
    Set r = Range(ListBox1.RowSource)
    r.Cells(i, 1).Offset(, 1) = TextBox1
    r.Cells(i, 1).Offset(, 2) = TextBox2
    End Sub
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Newbie
    Joined
    Oct 2010
    Posts
    2
    Location
    Thanks for your time, just what I wanted
    Pete

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Glad to help.
    You can mark you threads solved using the Thread Tools dropdown
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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