+ Reply to Thread
Results 1 to 3 of 3

Thread: Listbox to textbox via commandbutton

  1. #1
    Registered User
    Join Date
    09-09-2010
    Location
    Philadelphia PA
    MS-Off Ver
    Excel 2007
    Posts
    25

    Listbox to textbox via commandbutton

    Here is what I am trying to accomplish.

    I have a listbox (lbProducts) with a list of products and a set of 10 textboxes (txtProduct1 to txtProduct10) There is a CommandButton (btnSelect) in between listbox and textboxes.

    So, when the user clicks on an object in listbox and clicks on "btnSelect", the select object is copied to next available textbox, starting from txtProduct1.

    In short I want to allow user to select upto 10 objects from listbox and copy them to txtProduct 1 to txtProduct 10 which eventually will go into inputdata sheet.

    Please find the attached workbook for reference.

    Please Advise.
    Last edited by himanshu83; 09-14-2010 at 03:23 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Listbox to textbox via commandbutton

    Hello himanshu83,

    Here is the code for the UserForm. Clear all the code you have now and paste this into the UserForm.
    Option Explicit
    
    Private Sub btnCancel_Click()
      Unload Me
    End Sub
    
    Private Sub btnOk_Click()
    
    End Sub
    
    Private Sub btnSelect_Click()
    
      Dim Ctrl As Object
        
        For Each Ctrl In Me.Controls
          If Ctrl.Name Like "txtProduct#*" Then
            If Ctrl.Value = "" And lbProducts.ListIndex > -1 Then
               Ctrl.Value = lbProducts.List(lbProducts.ListIndex)
               Exit Sub
            End If
          End If
        Next Ctrl
        
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    09-09-2010
    Location
    Philadelphia PA
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Listbox to textbox via commandbutton

    Thanks a Lot Keith.. The code workes like magic

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0