+ Reply to Thread
Results 1 to 12 of 12

ListBox Selection to TextBox

  1. #1
    Forum Contributor
    Join Date
    02-26-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    286

    ListBox Selection to TextBox

    I Have a ListBox and TextBox on a UserForm . On selecting an item in the ListBox I wish to have a description for that item appear in the TextBox. If a different item is selected a different description appears in the TextBox. Once a final selection is made a Command Button will run a routine.
    What would be the code to show the description in the TextBox with each selection?
    Thanks Sandy

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: ListBox Selection to TextBox

    Hi gSandy
    Where is the description stored....This will get you started

    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    02-26-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    286

    Re: ListBox Selection to TextBox

    Hi Sintek,
    I was going to write the description within the code, see below. But this is not working! More help needed.
    Please Login or Register  to view this content.

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: ListBox Selection to TextBox

    Have a look at this code...Perhaps can amend to suite your requirements...Have no sample workbook to work with.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    02-26-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    286

    Re: ListBox Selection to TextBox

    It is getting closer. With the code below when I select an item in the ListBox it appears instantly in the TextBox, along with the note, just like I wanted.
    But it works for all items except the first item?
    I now wish to add a different note with each item in the list, i.e. "My note 2", "My note 3" etc. Maybe using an If statement or Select Case?

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-26-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    286

    Re: ListBox Selection to TextBox

    Hi Sintek,

    I have solved both problems with the code below. It now just needs tiding up.

    Thanks for your help in getting me started. Cheers Sandy.
    Please Login or Register  to view this content.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: ListBox Selection to TextBox

    How many items (and descriptions ) are there in your Listbox ?
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  8. #8
    Forum Contributor
    Join Date
    02-26-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    286

    Re: ListBox Selection to TextBox

    Up to 20.
    I have got Select Case working.

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: ListBox Selection to TextBox

    Up to 20.
    Putting all that text in the code itself is overkill.
    Better to put your items (columnA) and descriptions ColumnB) on a (hidden) sheet and use code below.
    This also makes it easier to make changes to items or descriptions without having to dive into your code every time.

    Please Login or Register  to view this content.
    Last edited by bakerman2; 04-25-2017 at 10:21 PM.

  10. #10
    Forum Contributor
    Join Date
    02-26-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    286

    Re: ListBox Selection to TextBox

    Thanks Bakerman2. That worked a treat, and a lot easier to modify/add to. Cheers Sandy.

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: ListBox Selection to TextBox

    You're welcome and thanks for rep+.

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: ListBox Selection to TextBox

    Glad you got it working, Thanks for rep points.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Populate (ca 200) Txtboxes depending on listbox selection, live-filter for listbox &1 more
    By InternInNeed in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-14-2016, 09:56 AM
  2. [SOLVED] Add each Listbox Selection to Textbox
    By coreytroy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2014, 07:17 PM
  3. [SOLVED] Focus from listbox selection to textbox gives an error
    By Jovica in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-23-2014, 05:54 PM
  4. [SOLVED] UserForm - How To Make TextBox Value Change Depending On ListBox Selection
    By ScotyB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-26-2013, 05:05 PM
  5. Replies: 12
    Last Post: 08-28-2012, 07:09 AM
  6. Multi select Listbox Items selection based on other Listbox item selection.
    By srinivassathi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-20-2011, 05:53 AM
  7. Textbox update with previous selection from listbox
    By Binsy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-29-2010, 05:03 PM

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.6.0 RC 1