+ Reply to Thread
Results 1 to 6 of 6

Get selection from ListBox and copy to TextBox (USERFORM)

  1. #1
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    Get selection from ListBox and copy to TextBox (USERFORM)

    Happy New Year
    And Thank you for taking a look at my problem.

    What i have:
    A Userform where I type a zip code in the textBox and while typing the ListBox shows the matching possibilities from a Range.
    The Range is merged cells from a Table where I have Zip code in Col 1 and City in Col 2.
    I can only search by ZipCode.

    Example workBook Uploaded.



    What I relly would like:
    - A Userform where I would like a way to type in the textBox while the ListBox shows the values from a Table with Zip code in Col 1 and City in Col 2.
    - While typing in TextBox the ListBox should only show matching possibilities.
    - I would like the option of searching by either Zip Code or City.
    - The ListBox should show Zip Code and Matching City (As in merged Cells on Sheet)
    - A way to Select the value from the ListBox to the TextBox.

    Any Help is much appreciated


    A Snip of my code so far:
    Please Login or Register  to view this content.
    Udklip.PNG
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Get selection from ListBox and copy to TextBox (USERFORM)

    Quote Originally Posted by nordicdust View Post

    What I relly would like:
    - A Userform where I would like a way to type in the textBox while the ListBox shows the values from a Table with Zip code in Col 1 and City in Col 2.
    - While typing in TextBox the ListBox should only show matching possibilities.
    - I would like the option of searching by either Zip Code or City.
    - The ListBox should show Zip Code and Matching City (As in merged Cells on Sheet)
    - A way to Select the value from the ListBox to the TextBox.
    Try this:
    Notes:
    1. searching in textbox is case insensitive, try typing '72 a'.
    2. to transfer value from listbox to textbox use doubleclick.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    Re: Get selection from ListBox and copy to TextBox (USERFORM)

    WOW Akuini

    That is absolutly Perfect :-)
    This will make my day so much much easier at work.

    I Try to use the keyboard as much as possible in my workbooks and less Mouse.

    When there is like 4 options in the ListBox, if I press the Key Down, the options turn blue (Marked)
    Is it possible to Set TextBox = The marked option in ListBox ? Then I could just press Tap to go to OK.

    I hope this makes sence :-)

    @Akuini
    I just thought that maybe the best solution was
    Please Login or Register  to view this content.
    Is that possible?
    Last edited by nordicdust; 01-05-2019 at 05:29 PM.

  4. #4
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Get selection from ListBox and copy to TextBox (USERFORM)

    Ok, see if this suits your needs.
    Steps:
    1. The user types something in the text box
    2. press tab > focus will go to the listbox
    3. use the up\down arrow > press Enter > textbox value = listbox value
    4. press tab > focus will go to the GO button

    Add these lines to the existing code:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    Re: Get selection from ListBox and copy to TextBox (USERFORM)

    Thank you Akuini

    This is perfect, I will mark this as Solved.

  6. #6
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Get selection from ListBox and copy to TextBox (USERFORM)

    Quote Originally Posted by nordicdust View Post
    Thank you Akuini

    This is perfect, I will mark this as Solved.
    You're welcome, glad to help.
    I modify the code a bit to limit the keypress (in the listbox) to Enter key.

    Please Login or Register  to view this content.
    Just a thought:
    I don't know what the OK button does, but to reduce the steps you need to take, you can just move the code (for your OK button) to the 'Private Sub Listbox_RESULTAT_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)'. That way you won't need the OK button anymore.
    For example:
    In the modified code above I add :
    Please Login or Register  to view this content.
    comment out the line to see what happen. I mean you can put in there the code to do what your OK button do .

+ 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. [SOLVED] Userform copy textbox value to different range depending on Combobox selection
    By icsiszer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-11-2018, 03:42 AM
  2. [SOLVED] ListBox Selection to TextBox
    By gsandy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-26-2017, 12:25 AM
  3. VBA - Userform - Listbox validation and Listbox to Textbox
    By stevefisher85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-04-2016, 07:11 AM
  4. Userform ListBox depending on a previous Listbox selection
    By Figolu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2015, 04:31 PM
  5. Userform ListBox depending on a previous Listbox selection
    By Figolu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-23-2015, 02:08 PM
  6. [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
  7. [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

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